[PGSQL] Should we use a singleton pattern for DAO class in postgres-mailbox? #5002
vttranlina
announced in
Announcements
Replies: 2 comments 2 replies
-
We could groom this and create an investigation task around it I think before engulfing hours into dev. But thanks for opening the discussion, it's needed I think :) |
Beta Was this translation helpful? Give feedback.
0 replies
-
Very first thought in my head: // create a Named bean e.g for PostgresSubscriptionMapper, and mark it as Singleton
// create a PostgresSubscriptionMapperFactory
public PostgresSubscriptionMapperFactory(@Named(NO_RLS) SubscriptionMapper subscriptionMapper, PostgresConfiguration postgresConfiguration) {
}
public SubscriptionMapper createSubscriptionMapper(MailboxSession session) {
if (postgresConfiguration.rowLevelSecurityEnabled()) {
create a new instance
} else {
return the singleton bean
}
}
@Override
public SubscriptionMapper createSubscriptionMapper(MailboxSession session) {
return postgresSubscriptionMapperFactory.createSubscriptionMapper(session);
} |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Currently, for each mailbox request,
James will create a new DAO for each Mailbox session.
https://github.com/apache/james-project/blob/a27db56f89252e8686b54a388a92b0631274342c/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/PostgresMailboxSessionMapperFactory.java#L49
The reason for that is when we use RLS for the mailbox table (get Connection for each domain)
We can optimize it when we disable RLS, we can create a singleton DAO
I can imagine, it will be quite verbose in the source code.
WDYT?
Beta Was this translation helpful? Give feedback.
All reactions