snpdb/annotation: fix N+1 queries on the variant details page #1730 - #1732
Merged
Conversation
The variant page sample table refetched Classification (wide evidence JSONB) and lab per row, and its locus counts table fetched Variant without the locus/sequence rows that str(v) reaches through to. The transcript table (variant page, classification autopopulate, classification detail) loaded gene_version lazily over a loop that pulls every transcript version for the variant's gene symbols.
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.
🤖 Written by Claude.
Addresses part of #1730 — the snpdb/annotation fixes that are just
select_related. Split out of #1727; the classification half is in a separate PR.Variant details page
latest_for_user, which applies noselect_related, so each row refetchedClassification— including the wideevidenceJSONB — pluslab.Variantrows without their locus/sequence rows, andstr(v)then costs three queries each vialocus.contig.name,locus.ref.seqandalt.seq.Transcript table
gene_versionloaded lazily over a loop that pulls every transcript version for the variant's gene symbols — often 50-300 rows. Used by the variant page, classification autopopulate and the classification detail view.Not included
The grid items in the issue (the AlleleLiftover grids, the variant tag
can_write) need thepre_render(qs)hook to bulk-load a page's objects into a dict. That is a consistent little pattern rather than a one-line change, so it is better as its own PR than bolted onto this one.Testing
python3 manage.py test --keepdb snpdb.tests annotation.tests— 551 tests pass.