Skip to content

perf: 6-54x faster cold-cache rebuild for /all/ endpoints#151

Merged
deanmoses merged 3 commits intomainfrom
perf/faster-cold-cache-rebuild
Apr 5, 2026
Merged

perf: 6-54x faster cold-cache rebuild for /all/ endpoints#151
deanmoses merged 3 commits intomainfrom
perf/faster-cold-cache-rebuild

Conversation

@deanmoses
Copy link
Copy Markdown
Collaborator

Summary

Slash cold-cache response times for the four /all/ endpoints from ~30s aggregate to ~3-5s on production (6-54x faster per endpoint) by replacing deep ORM prefetch with bulk values_list() queries, caching get_minimum_display_rank() per rebuild, and avoiding full object hydration.

  • titles: 3.59s → 0.54s (6.6x)
  • models: 3.17s → 0.26s (12.2x)
  • manufacturers: 1.37s → 0.09s (15.2x)
  • people: 1.08s → 0.02s (54x)
  • Also extracts a shared PageHeader component (adopted in 27 files) and adds docstrings/named constants to the bulk-query code

Test plan

  • make test passes (backend + frontend)
  • Deploy to staging, clear cache, hit each /all/ endpoint and confirm response shape is unchanged
  • Verify cold-cache load times are significantly faster than before
  • Spot-check a few detail pages to confirm PageHeader renders correctly (title, breadcrumbs)

🤖 Generated with Claude Code

deanmoses and others added 3 commits April 6, 2026 00:07
The /all/ endpoints (titles, models, manufacturers, people) take ~30s
on production when the cache is cold — after every deploy or edit.
Three optimizations reduce this to ~3-5s estimated:

1. Cache get_minimum_display_rank() per-rebuild — the Constance DB
   lookup was called per-item (6k+ times). Adding a min_rank kwarg
   to _extract_image_urls() lets callers hoist it out of the loop.

2. Replace deep ORM prefetch + Python iteration with bulk
   values_list() queries on through tables. Instead of hydrating
   6k+ full model objects with all M2M relations, query each
   dimension separately into lightweight dicts.

3. Use values_list() for the main query instead of full ORM object
   instantiation. For 6.8k models with 8 select_related joins,
   this alone saves ~0.37s locally (0.44s → 0.07s).

Local cold-cache times (before → after):
  titles:        3.59s → 0.54s  (6.6x)
  models:        3.17s → 0.26s  (12.2x)
  manufacturers: 1.37s → 0.09s  (15.2x)
  people:        1.08s → 0.02s  (54x)

Response shapes and cache infrastructure are unchanged.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add docstrings explaining the bulk-query pattern, replace magic tuple
indices with named constants (T_ID, M_SLUG, etc.), and remove dead
model_year/model_rating dicts from list_all_titles.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Deduplicate the <header> + <h1> block (font-size-7, weight 700,
color-text-primary) that was copy-pasted across 27 files. The new
PageHeader component accepts title, optional breadcrumbs (renders
Breadcrumb internally), optional children snippet, and CSS custom
properties for margin overrides (--page-header-mb, --page-header-title-mb).

Adopted in 3 shared components (DetailPage, EntityDetailLayout,
TaxonomyListPage), 16 [slug]/+layout.svelte files, and 8 list/detail
pages. Exports Crumb type from Breadcrumb.svelte for reuse.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@deanmoses deanmoses added enhancement New feature or request refactor Production code changes that don't alter behavior labels Apr 5, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 5, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 5d3b67e0-6bf3-4bdb-8845-31982a63a80a

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch perf/faster-cold-cache-rebuild

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@deanmoses deanmoses merged commit b3e3586 into main Apr 5, 2026
6 checks passed
@deanmoses deanmoses deleted the perf/faster-cold-cache-rebuild branch April 5, 2026 22:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request refactor Production code changes that don't alter behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant