Skip to content

Pre-resolve functional classification membership on the VA-Spec and NDJSON routes #657

Open

Description

@bencap

The VA-Spec and NDJSON routes load every variant in each calibration range just to check which range one variant falls in. This issue replaces that with a single up-front query, so those routes stop loading thousands of rows they don't need.

Problem

_classification_contains_variant in lib/annotation/classification.py checks whether a variant falls in a functional classification. It prefers a pre-resolved set of classification ids, which is an O(1) check, and falls back to variant in functional_classification.variants. The fallback loads every variant in the range. Callers that don't pre-resolve pay that cost per classification, and routes eager-load ScoreCalibrationFunctionalClassification.variants to avoid an N+1 (for example routers/score_calibrations.py:749).

The cost lands on the VA-Spec and NDJSON routes: the study-result, functional-statement and pathogenicity-statement routes under /variants/{urn} and /mapped-variants/{urn}, and the score set pathogenicity NDJSON route.

Scope

  • Pre-resolve containing classification ids for every caller, with one query against score_calibration_functional_classification_variants keyed by the variant ids in the request.
  • Remove the ORM fallback from _classification_contains_variant, so the id set is required.
  • Drop the selectinload(...variants) options that exist only for the membership check.

Acceptance criteria

  • No caller of functional_classification_of_variant or pathogenicity_classification_of_variant loads ScoreCalibrationFunctionalClassification.variants.
  • A query-count test on the score set pathogenicity NDJSON route asserts a constant number of queries as the variant count grows.
  • Existing tests/lib/annotation coverage passes unchanged.

Activity

  1. added theissue type on Feb 13, 2026
  2. changed the issue type fromtoon Feb 13, 2026
  3. added this to the R2026.4 milestone on Sep 24, 2026
  4. changed the title [-]Optimize Variant Classification Functions to Avoid ORM Relationship Loading[/-] [+]Pre-resolve functional classification membership on the VA-Spec and NDJSON routes[/+] on Sep 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    app: backendTask implementation touches the backend

    Type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions