Batch etsource cache reads with fetch_multi to reduce N+1 queries#1748
Open
aaccensi wants to merge 1 commit into
Open
Batch etsource cache reads with fetch_multi to reduce N+1 queries#1748aaccensi wants to merge 1 commit into
aaccensi wants to merge 1 commit into
Conversation
MeritOrder collapses 6 individual cache fetches into one fetch_multi call. Molecules does the same for its 2 keys. Both use Thread.current to ensure fetch_multi runs at most once per request. Closes #1747
This file contains hidden or 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
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.
Context
Since adopting Solid Cache, several controller actions that trigger a GQL calculation are flagged by Sentry as N+1 queries. This was not visible before because Memcached round-trips are cheap and don't use SQL; with Solid Cache every cache operation is a SQL query. The fix implemented is cache-backend agnostic.
Implemented changes
MeritOrdercollapses 6 individual cache fetches into one fetch_multi call.Moleculesdoes the same for its 2 keys. Both use Thread.current to ensure fetch_multi runs at most once per request.Notice that
FeverandReconciliationwere not changed:Feverhas a single key so batching adds no value, and Reconciliation has a dependency between its two keys (reconciliation_hashis computed usingreconciliation_carriers, so they cannot be fetched in a singlefetch_multi)Related
Closes #1747
Checklist