This repository was archived by the owner on Jun 13, 2025. It is now read-only.
badges: fetch branch head and associated commit in same query#1275
Closed
matt-codecov wants to merge 1 commit intomainfrom
Closed
badges: fetch branch head and associated commit in same query#1275matt-codecov wants to merge 1 commit intomainfrom
matt-codecov wants to merge 1 commit intomainfrom
Conversation
Contributor
✅ Sentry found no issues in your recent changes ✅ |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
fetching a badge uses 4+ queries:
select * from owners where owners.name = ${request.username} and owners.service = ${request.service}select * from repos where repos.ownerid = ${owner.ownerid} and repos.name = ${request.repo_name}select * from branches where branches.name = ${request.branch_name} and branches.repo_id = ${repo.repoid}select * from commits where commits.commitid = ${branch.head} and commits.repoid = ${repo.repoid}(side note: the first two queries actually have a
LIMIT 21which suggests they were logged while in queryset form. i am guessing a subsequent.first()call happens but doesn't need to re-run the query?)in principle they could be folded into one:
doing so might improve the performance of the badges endpoint. don't know
this PR doesn't actually do that:
ownersandreposqueries happen, so those are left outbranchesandcommitsdon't actually have a FK relationship, Django won't perform a join between theminstead, this PR would result in SQL that looks something like:
maybe adding
LIMIT = 1to the subquery would help. not surei don't know whether the performance would actually improve, so i am closing this. just created a PR to document the result of this little exploration.