-
Notifications
You must be signed in to change notification settings - Fork 27
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
[#148409] Reduce number of DB queries on Facility timeline page #1899
Merged
vandrijevik
merged 9 commits into
master
from
va-improve-performance-on-facility-timeline-page
Mar 14, 2019
Merged
[#148409] Reduce number of DB queries on Facility timeline page #1899
vandrijevik
merged 9 commits into
master
from
va-improve-performance-on-facility-timeline-page
Mar 14, 2019
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The indirection and hack (in ReservationsController, public_timeline calls timeline) here are not worth the DRY aspect, and the two pages are very different, so decoupling their implementation allows us to evolve and optimize the controller methods separately as it makes sense.
The method #offline? needs to check whether there are any current offline reservations. By refactoring to an association and using #present?, Rails will memoize the association and check without another DB query.
73878b1
to
633bb82
Compare
rolfrussell
approved these changes
Mar 14, 2019
joshea0
pushed a commit
to SquaredLabs/nucore-uconn
that referenced
this pull request
Mar 18, 2020
…orks#1899) * Refactor away Timelinable module The indirection and hack (in ReservationsController, public_timeline calls timeline) here are not worth the DRY aspect, and the two pages are very different, so decoupling their implementation allows us to evolve and optimize the controller methods separately as it makes sense. * Separate facility and public schedule partials and get rid of conditional * Refactor association-like methods on Schedule to associations * Use .size on association in _schedule so we don’t have to execute a count every time * Eliminate N+1 for loading alerts when displaying timelines * Fold single-use partial _relay_switch into only call site * Avoid N+1 for relays on facility timeline * Avoid two unnecessary queries just to check if an instrument is offline The method #offline? needs to check whether there are any current offline reservations. By refactoring to an association and using #present?, Rails will memoize the association and check without another DB query. * Appease rubocop’s style preferences
chrixp
pushed a commit
to SquaredLabs/nucore-uconn
that referenced
this pull request
Oct 21, 2020
…orks#1899) * Refactor away Timelinable module The indirection and hack (in ReservationsController, public_timeline calls timeline) here are not worth the DRY aspect, and the two pages are very different, so decoupling their implementation allows us to evolve and optimize the controller methods separately as it makes sense. * Separate facility and public schedule partials and get rid of conditional * Refactor association-like methods on Schedule to associations * Use .size on association in _schedule so we don’t have to execute a count every time * Eliminate N+1 for loading alerts when displaying timelines * Fold single-use partial _relay_switch into only call site * Avoid N+1 for relays on facility timeline * Avoid two unnecessary queries just to check if an instrument is offline The method #offline? needs to check whether there are any current offline reservations. By refactoring to an association and using #present?, Rails will memoize the association and check without another DB query. * Appease rubocop’s style preferences
joshea0
pushed a commit
to SquaredLabs/nucore-uconn
that referenced
this pull request
Oct 23, 2020
…orks#1899) * Refactor away Timelinable module The indirection and hack (in ReservationsController, public_timeline calls timeline) here are not worth the DRY aspect, and the two pages are very different, so decoupling their implementation allows us to evolve and optimize the controller methods separately as it makes sense. * Separate facility and public schedule partials and get rid of conditional * Refactor association-like methods on Schedule to associations * Use .size on association in _schedule so we don’t have to execute a count every time * Eliminate N+1 for loading alerts when displaying timelines * Fold single-use partial _relay_switch into only call site * Avoid N+1 for relays on facility timeline * Avoid two unnecessary queries just to check if an instrument is offline The method #offline? needs to check whether there are any current offline reservations. By refactoring to an association and using #present?, Rails will memoize the association and check without another DB query. * Appease rubocop’s style preferences
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Release Notes
Reduce number of DB queries on Facility timeline page
Additional Context
Removes a few low-hanging N+1 fruits in the partials that we render for each instrument on the Facility’s timeline page, and reduces the typical number of queries per instrument from 10:
Before
to 5:
After
Unfortunately, the remaining N+1 queries that we have (for an instrument’s reservations) are not trivial to remove because they depend on the selected date, so they can’t be preloaded. If this PR is not enough of a performance boost for the facility timeline page, we can at least try to combine the queries which load reservations for an instrument into one (instead of 5 per instrument).