Skip to content

Section authorization: Optimize method to make it faster - #2656

Merged
kevinrobinson merged 5 commits into
masterfrom
perf/section-authorization
Oct 2, 2019
Merged

kevinrobinson merged 5 commits into
masterfrom
perf/section-authorization

Conversation

@kevinrobinson

@kevinrobinson kevinrobinson commented Oct 2, 2019 •

Copy link
Copy Markdown
Contributor

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)

Checklists

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
@kevinrobinson

Copy link
Copy Markdown
Contributor Author

selfie

@kevinrobinson
kevinrobinson merged commit edffab0 into master Oct 2, 2019
@kevinrobinson
kevinrobinson deleted the perf/section-authorization branch October 2, 2019 15:56
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.

1 participant