Skip to content
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

Use lightweight validation responses for progress stats #669

Merged
merged 2 commits into from
Jan 16, 2025

Conversation

jsharkey13
Copy link
Member

Prior to this commit, we loaded the full attempt JSON data from the database for every question attempt the user had made - but at no point do we need this data. We can avoid a great deal of deserialising if we instead load just the lightweight attempts, which we can do using existing queries (plus some plumbing).

One bug was revealed; although the database query sorts the lightweight attempts identically to the full attempts, and the structure of the nested Maps is identical - the Lightweight code path used HashMaps but the full validation response code path used LinkedHashMaps. The former do not preserve insertion order, and so were removing this sorting. The existing uses of the data clearly did not need sorted attempts, but the My Progress stats page does. The cost of switching to the LinkedHashMap is small and only on creation; iterating over it as we do is much faster. This now preserves the (costly) sorting done in the DB.

Prior to this commit, we loaded the full attempt JSON data from the
database for every question attempt the user had made - but at no point
do we need this data. We can avoid a great deal of deserialising if
we instead load just the lightweight attempts, which we can do using
existing queries (plus some plumbing).

One bug was revealed; although the database query sorts the lightweight
attempts identically to the full attempts, and the structure of the
nested Maps is identical - the Lightweight code path used HashMaps but
the full validation response code path used LinkedHashMaps. The former
do not preserve insertion order, and so were removing this sorting.
The existing uses of the data clearly did not need sorted attempts,
but the My Progress stats page does. The cost of switching to the
LinkedHashMap is small and only on creation; iterating over it as we do
is much faster. This now preserves the (costly) sorting done in the DB.
@jsharkey13
Copy link
Member Author

In my testing, this was a little over 50% faster for users with large numbers of question attempts (because finding them in the database is still slow), but saves a (very) large amount of CPU work doing unnecessary deserialising!

Copy link

codecov bot commented Jan 15, 2025

Codecov Report

Attention: Patch coverage is 22.22222% with 7 lines in your changes missing coverage. Please review.

Project coverage is 34.37%. Comparing base (7c11249) to head (3b20742).
Report is 10 commits behind head on master.

Files with missing lines Patch % Lines
...m/cl/dtg/segue/api/managers/StatisticsManager.java 0.00% 4 Missing ⚠️
...k/ac/cam/cl/dtg/isaac/quiz/PgQuestionAttempts.java 50.00% 2 Missing ⚠️
...cam/cl/dtg/segue/api/managers/QuestionManager.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master     #669   +/-   ##
=======================================
  Coverage   34.37%   34.37%           
=======================================
  Files         521      521           
  Lines       23478    23475    -3     
  Branches     2875     2875           
=======================================
  Hits         8070     8070           
+ Misses      14596    14593    -3     
  Partials      812      812           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@axlewin axlewin merged commit 75dc702 into master Jan 16, 2025
3 checks passed
@axlewin axlewin deleted the feature/lightweight-attempts-progress-page branch January 16, 2025 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants