Fragment caching of user-independent page sections

Open
#2,654 0 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
53/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
django, python, redis

Research direction

Start with the Django templates and view code for view_gene_symbol, view_variant, view_allele, and ontology_term, then audit each proposed section for user-specific data. Add fragment caching one page at a time with keys that include the object, genome build, and annotation version where relevant. Compare query counts on a second render using vg page <url> --queries; done means user-independent fragments are shared safely and the repeated render uses fewer queries.

Written by the indexing model from the issue text.

Description

🤖 Written by Claude

With the per-user page frame out of the page body (#2007), the expensive parts of our heaviest pages are chunks that depend only on an object, a genome build and the annotation version: the annotation tables on the variant page, the gene summary and transcript table on the gene page, ontology term detail. Nothing in the codebase uses Django's {% cache %} tag yet, and the compiled-template cache is already on (Django's cached loader is the default with APP_DIRS), so fragments are the next step.

Why fragments rather than whole pages. Django's LoginRequiredMiddleware reads request.user before every view, which reads the session and makes SessionMiddleware add Vary: Cookie, so cache_page on a logged-in page is a per-session cache whatever the body does. A {% cache %} fragment sits inside the render with an explicit key, so it is shared across users without touching that, and the audit (does this chunk read the user?) is per fragment rather than per page.

Proposed

  • A key convention: {% cache timeout name obj.pk genome_build.pk vav.pk %}, with the VariantAnnotationVersion pk in the key for anything derived from annotation so a version switch is a new entry rather than an invalidation. Anything derived from classifications or tags takes a short timeout or a modified timestamp in the key.
  • A fragment never reads the user, a user setting, or filter_for_user results; those sections stay outside it or become ajax. vg page <url> --queries before and after shows the query count fall on the second render.
  • First pages: view_gene_symbol, view_variant / view_allele annotation sections, ontology_term. One PR per page.

Redis is shared across gunicorn and celery, so a fragment keyed only on object and build goes stale when annotation changes under it; the VAV pk in the key is what prevents that.

Related: #2655 (shared whole-page cache) and #1360 / #695 (public pages) will reuse the same convention.

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.