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

optimize Section#summarize_without_students #30552

Merged
merged 1 commit into from Aug 30, 2019

Conversation

wjordan
Copy link
Contributor

@wjordan wjordan commented Aug 30, 2019

This PR improves the performance of section#summarize_without_students, used by the home page for signed-in users within a section:

  • Remove unnecessary 'ORDER BY' relation from scope to improve query.
  • Use #size instead of #length to use COUNT instead of fetching full association.

I've also replaced uniq with distinct, the uniq alias is deprecated and will be removed in Rails 5.1.

Students within large sections (10k+ students) were seeing ~20 second load times for the home page due to this unoptimized query. Benchmarking #summarize_without_students against a single section of 10,000 students, this PR provides a ~70x improvement, which should make this page once again usable for students in large sections.

- Remove unnecesary 'ORDER BY' relation from scope to improve query.
- Use `#size` instead of `#length` to use `COUNT` instead of
  fetching full association collection.
@codecov-io
Copy link

codecov-io commented Aug 30, 2019

Codecov Report

Merging #30552 into staging will increase coverage by 3.58%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff             @@
##           staging   #30552      +/-   ##
===========================================
+ Coverage    73.21%    76.8%   +3.58%     
===========================================
  Files         2058      680    -1378     
  Lines       112978    27786   -85192     
  Branches      3495        0    -3495     
===========================================
- Hits         82721    21340   -61381     
+ Misses       26995     6446   -20549     
+ Partials      3262        0    -3262
Flag Coverage Δ
#integration ?
#storybook ?
#unit ?
Impacted Files Coverage Δ
dashboard/app/models/sections/section.rb 97.91% <100%> (+0.01%) ⬆️
lib/cdo/poste.rb 75.73% <0%> (-0.6%) ⬇️
apps/src/applab/AppLabView.jsx
.../src/lib/ui/accounts/ChangeUserTypeModal.story.jsx
apps/src/applab/GoogleChart.js
...s/src/lib/ui/accounts/manageLinkedAccountsRedux.js
apps/src/lib/ui/accounts/DeleteAccountHelpers.jsx
...c/applab/designElements/ColorPickerPropertyRow.jsx
...mplates/teacherDashboard/SelectSectionDropdown.jsx
...ps/src/templates/instructions/InputOutputTable.jsx
... and 1370 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e653436...dad2b44. Read the comment docs.

Copy link
Member

@davidsbailey davidsbailey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me. once again, nice find!

@wjordan wjordan merged commit db39f21 into staging Aug 30, 2019
@wjordan wjordan deleted the section_summarize_optimize branch August 30, 2019 22:29
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.

None yet

3 participants