SEAB-7089: Fix slow-loading user profile "Activity" section #6098
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR changes the performance profile of the event retrieval endpoints, thus fixing the very slow load times of the "Activity" sections of certain user profile pages.
To retrieve events, the webservice synthesizes a
CriteriaQuery
, which, previously, results in a massivejoin
:The join "pulls in" lots of seemingly-unnecessary information, like versions, because, although it isn't being used to determine which
Event
s to select, it's needed to construct fully-formedEvent
s from the results.At some point between 15/Oct/2024 and 2/Nov/2024, the database changed so that, for users with lots of events, this join performs poorly and induces the observed delay. That is, on the 15/Oct db, the query is fast, and on the 2/Nov db, it is very slow. I confirmed this behavior by loading prod db dumps onto my local 1.17 build.
I'm not sure of the root cause. Could be that the involved data now exceeds some sort of internal threshold/limit in the db server, causing the query planner to do a worse job, or inducing the server to use a different internal data structure that doesn't perform as well. Or maybe something else. IMHO, it's potentially not the best use of our time to investigate more deeply, could take a while and might not reveal anything actionable...
This PR changes the query to retrieve a list of Event IDs, simplifying the above join to:
The resulting list of Event IDs is then converted to a list of Events in a subsequent query.
For users with many Events, the new scheme is much much faster. However, it's unchanged to negligibly slower for users that have few events. Wall clock time for http://localhost:4200/api/events/user-id?eventSearchType=PROFILE with this PR running locally, for different users:
Same test, running on local develop build:
Review Instructions
Confirm that the "Activity" section of the user profile pages is responding fast enough, and contains the correct information, sorted in the correct order. Make sure to check when you are both logged-in and logged-out. Suggested urls: https://qa.dockstore.org/users/denis-yuen etc
Issue
https://ucsc-cgl.atlassian.net/browse/SEAB-7089
Security and Privacy
If there are any concerns that require extra attention from the security team, highlight them here and check the box when complete.
e.g. Does this change...
Please make sure that you've checked the following before submitting your pull request. Thanks!
mvn clean install
@RolesAllowed
annotation