Skip to content

perf(sponsors): add indexes and fragment caching for sponsors page - #2803

Merged
mroderick merged 3 commits into
masterfrom
feature/add-sponsors-indexes
Aug 31, 2026
Merged

perf(sponsors): add indexes and fragment caching for sponsors page#2803
mroderick merged 3 commits into
masterfrom
feature/add-sponsors-indexes

Conversation

@mroderick

@mroderick mroderick commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

Adds two PostgreSQL indexes and per-sponsor fragment caching to the sponsors page to address the slow SponsorsController#index reports.

Database indexes

SponsorsController#index loads active sponsors ordered by updated_at, and SponsorsSearch (admin sponsors list) orders by lower(sponsors.name). Both queries previously used a sequential scan plus an explicit sort.

Local EXPLAIN ANALYZE with ~1,160 rows:

Query Before After
Active sponsors by updated_at Seq Scan + Sort, ~1.45 ms Index Scan, ~0.31 ms
Admin order by lower(name) Seq Scan + Sort, ~2.86 ms Index Scan, ~0.05 ms

View allocations

Scout APM showed some requests hitting ~5M allocations, 95% in view code. Profiling the sponsor partial showed CarrierWave creating uploader/version/sanitized-file objects for every sponsor on every render.

Splitting the sponsor partial into a single-sponsor partial and rendering the collection with cached: true drops warm-cache allocations for the partial by ~80% (from ~225k objects to ~44k objects locally). Cache keys are based on each sponsor's updated_at, so edits invalidate automatically.

The indexes are added concurrently with if_not_exists: true, so the migration is safe to re-run.

@mroderick
mroderick force-pushed the feature/add-sponsors-indexes branch from 4c18967 to 831d711 Compare August 10, 2026 07:24
@mroderick mroderick changed the title fix(db): add sponsor indexes for active scope and search perf(sponsors): add indexes and fragment caching for sponsors page Aug 10, 2026
@mroderick
mroderick marked this pull request as ready for review August 11, 2026 15:44
@mroderick
mroderick requested a review from olleolleolle August 30, 2026 05:29

@olleolleolle olleolleolle left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat!

@mroderick
mroderick enabled auto-merge August 31, 2026 06:34
@mroderick
mroderick merged commit 8a1304e into master Aug 31, 2026
9 checks passed
@mroderick
mroderick deleted the feature/add-sponsors-indexes branch August 31, 2026 06:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants