Classification JSON export: as_json recomputes per-lab evidence keys, permissions and settings for every row

Open
#2,870 3 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
django, python

Research direction

Start in ClassificationModification.as_json, then trace populate_classification_json and the named evidence key, permission, and per-row lookup paths. Profile an export before changing anything, focusing on work repeated for the same lab, user, or batch. Measure it again afterward; done means those repeated computations and lookups are reused while the exported JSON remains correct.

Written by the indexing model from the issue text.

Description

🤖 Written by Claude

The classification grouping JSON export spends about 39 ms per row in ClassificationModification.as_json. That is about 50 minutes for 75k groupings on a test deployment. Database time is only about 6% of that: the rest is recomputing things that are the same for many rows.

Profile of 500 rows (19.7 s):

  • About 50%: the evidence key map. populate_classification_json → Classification.get_visible_evidence → Classification.evidence_keys → EvidenceKeyMap.with_overrides builds and deep-copies the whole evidence key map with the lab's overrides for every row, though an export covers only a handful of labs.
  • About 13%: can_write. It runs two guardian permission queries for every row.
  • 13 queries per row in total. The repeats per row are lab and organisation classification settings (the same few labs), resolved variant info, grouping entry, overlap contribution, condition text match and the user's groups.

Why not store the JSON: the published evidence is already stored (published_evidence). The rest of the output depends on the viewing user (hidden evidence by share level, can_write, messages) and on data that changes after publishing (allele matching and resolved HGVS, condition resolution, withdrawn status, flags, lab names, evidence key definitions). A stored copy would need clearing on every one of those changes.

Fix: compute each of these once per lab, user or batch for an export, and load the per-row lookups once per batch. Measure before and after.

Dominant language
Python
Stars
31
Forks
4
Avg merge
4h 52m
Merged PRs (30d)
183

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from SACGF/variantgrid

All issues in SACGF/variantgrid

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.