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

Section authorization: Optimize method to make it faster #2656

merged 5 commits into from Oct 2, 2019


Copy link

@kevinrobinson kevinrobinson commented Oct 2, 2019

Who is this PR for?

Educators with section assignments

What problem does this PR fix?

#2654 centralizes section authorization, and makes more use of these methods that previously. This slowed down the section page for queries like authorized { Section.all }.

What does this PR do?

Adds two optimizations, adapted from #why_authorized_for_student?, comparing foreign key values rather than model values to remove that query, and adding a #to_a call to the end of the association, which causes Rails to cache the result of that query across calls. I'm not sure why this influences Rails' caching, but it does and PerfTests here show the same thing as with #why_authorized_for_student?.

Also adds minimal smoke tests to PerfTest methods, just verifying that they still run and don't break. It does not make assertions about performance.

Screenshot (if adding a client-side feature)

puts PerfTest.section_authorization_pattern(0.01);nil

# before
1%,  median: 1917ms    p95: 2490ms

# after
 1%, median:  417ms    p95:  613ms
 5%, median:    2ms    p95:  511ms
10%, median:    2ms    p95:  518ms
(caveat: distribution is bimodal since some educators don't have sections)


Which features or pages does this PR touch?

  • Section
  • Authorization

Does this PR use tests to help verify we can deploy these changes quickly and confidently?

  • Manual testing made more sense here

@kevinrobinson kevinrobinson changed the title Perf/section authorization Section authorization: Optimize method to make it faster Oct 2, 2019
Copy link
Contributor Author

@kevinrobinson kevinrobinson commented Oct 2, 2019


@kevinrobinson kevinrobinson merged commit edffab0 into master Oct 2, 2019
1 check passed
@kevinrobinson kevinrobinson deleted the perf/section-authorization branch Oct 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

Successfully merging this pull request may close these issues.

None yet

1 participant