-
Notifications
You must be signed in to change notification settings - Fork 21
feat(backend): cache database and graphql api per user; move web -in/out from database to session #5196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
…2 into fix/cache_per_user
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces a per-user caching layer for Database and GraphQL API instances and shifts session/user tracking out of raw Database calls into a dedicated GraphqlSession class.
- Added
GraphqlSession
andGraphqlSessionFieldFactory
to centralize session logic and cache heavy objects per user. - Updated
SqlDatabase
andDatabase
interfaces to replacesetActiveUser
/becomeAdmin
withrunAsUser
/runAsAdmin
. - Refactored controllers, API factories, and almost all tests to use
GraphqlSession
or the newSqlDatabase(String, boolean)
constructor.
Reviewed Changes
Copilot reviewed 56 out of 56 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
backend/molgenis-emx2/src/main/java/org/molgenis/emx2/DatabaseListener.java | Added databaseChanged flag and getter to track full-DB changes. |
backend/molgenis-emx2/src/main/java/org/molgenis/emx2/Database.java / SqlDatabase.java | Removed setActiveUser /becomeAdmin , added runAsUser /runAsAdmin . |
backend/molgenis-emx2-webapi/src/main/java/org/molgenis/emx2/web/MolgenisSessionManager.java / MolgenisSession.java | Switched from manual DB wrappers to MolgenisSession subclass of GraphqlSession . |
backend/molgenis-emx2-graphql/src/main/java/org/molgenis/emx2/graphql/GraphqlSession.java | New session class with Caffeine caches for DB and GraphQL instances. |
backend/molgenis-emx2-graphql/src/main/java/org/molgenis/emx2/graphql/GraphqlApiFactory.java / GraphqlSessionFieldFactory.java | Adapted GraphQL factory to use GraphqlSession in field definitions. |
Multiple test files | Updated imports and instantiation to use SqlDatabase or GraphqlSession . |
Comments suppressed due to low confidence (3)
backend/molgenis-emx2/src/main/java/org/molgenis/emx2/DatabaseListener.java:29
- [nitpick] Rename
getDatabaseChanged()
toisDatabaseChanged()
to follow standard boolean getter naming conventions.
public boolean getDatabaseChanged() {
backend/molgenis-emx2-graphql/src/main/java/org/molgenis/emx2/graphql/GraphqlSession.java:33
- Using a static
TaskService
may lead to shared mutable state across sessions; consider making it instance-based or verifying thread-safety.
private static TaskService taskService = new TaskServiceInMemory();
@@ -21,7 +21,10 @@ public class MolgenisSessionManager { | |||
private static final Logger logger = LoggerFactory.getLogger(MolgenisSessionManager.class); | |||
private Map<String, MolgenisSession> sessions = new ConcurrentHashMap<>(); | |||
|
|||
public MolgenisSessionManager() {} | |||
public MolgenisSessionManager() { | |||
// set static settigs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct spelling in the comment: 'settigs' should be 'settings'.
// set static settigs | |
// set static settings |
Copilot uses AI. Check for mistakes.
Caffeine.newBuilder().maximumSize(1000).expireAfterAccess(5, TimeUnit.MINUTES).build(); | ||
private static Cache<String, GraphQL> schemaApiCachePerUser = | ||
Caffeine.newBuilder().maximumSize(1000).expireAfterAccess(5, TimeUnit.MINUTES).build(); | ||
private static Cache<String, GraphQL> databaseApiCachePerUser = | ||
Caffeine.newBuilder().maximumSize(1000).expireAfterAccess(5, TimeUnit.MINUTES).build(); | ||
private static TaskService taskService = new TaskServiceInMemory(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expose settings to (runtime) config
demo:
todo: