Avoid duplicated hot-path User and ServiceProvider queries#6058
Merged
mitchellhenke merged 3 commits intomainfrom Mar 14, 2022
Merged
Avoid duplicated hot-path User and ServiceProvider queries#6058mitchellhenke merged 3 commits intomainfrom
mitchellhenke merged 3 commits intomainfrom
Conversation
bb4ac2c to
e874483
Compare
d57ede3 to
135bb60
Compare
changelog: Internal, Performance, Re-use existing database query results to avoid duplicative work
Co-authored-by: Zach Margolis <zachmargolis@users.noreply.github.com>
135bb60 to
d53dc64
Compare
e22242e to
76023ab
Compare
Merged
This was referenced Mar 17, 2022
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.
User.findandServiceProvider.findare two of our most frequent queries. Though they're fast, they make up a significant portion of total Postgres timePart of that is due to querying for a ServiceProvider by issuer and User by id when adding SP cost. This PR lifts the queries out of
Db::SpCost::AddSpCostand puts the responsibility on callers of the function to provide all of the data ahead of time. For the most part, we are querying the issuer insp_session, whichcurrent_sphas probably already done.It gets a little weird in doc auth with having to adjust the delegation and moving
current_spto a public method, but I think it's worth it.There's opportunity to apply a similar pattern to
IdentityLinkerwhich accepts anissuer, but that can be saved for a followup if we're happy with the kind of adjustments being made here.