Skip to content

perf: cache /v1/pub/versions in Redis (cherry-pick #1281 to prod)#1285

Merged
hubsmoke merged 2 commits into
mainfrom
hotfix/cache-pub-versions-prod
Apr 29, 2026
Merged

perf: cache /v1/pub/versions in Redis (cherry-pick #1281 to prod)#1285
hubsmoke merged 2 commits into
mainfrom
hotfix/cache-pub-versions-prod

Conversation

@hubsmoke

Copy link
Copy Markdown
Member

Cherry-pick of #1281 (already merged to develop, verified working on dev) to fix dpid.org/ page load times in production.

Why cherry-pick instead of develop→main

The pending develop→main promotion (#1284) bundles 41 commits including a Prisma 4.10.1 → 6.15.0 major-version upgrade with no documented rationale and only CodeRabbit review. Shipping that needs careful babysitting; this surgical cherry-pick fixes the user-reported slowness today without taking on that risk.

Verified on dev (post-#1281 deploy)

URL: nodes-api-dev.desci.com/v1/pub/versions/<uuid> (dpid=3, 1 version, 453B payload)
call 1 (cold):  646ms
call 2 (warm):  114ms
call 3 (warm):  114ms
call 4 (warm):  107ms

6x speedup on a small payload. PR description's 7s→<100ms claim should hold for the larger 13-version dpid 1077 (4.6KB) which is the original symptom.

Scope

Two commits, 3 files:

  • desci-server/src/controllers/raw/versions.ts — wraps getIndexedResearchObjects in getOrCache with 1-day TTL
  • desci-server/src/controllers/nodes/publish.ts — invalidates indexed-versions-{uuid} cache on publish
  • desci-server/src/scripts/warm-versions-cache.ts — optional pre-warm script (run post-deploy to eliminate cold first-hit per dpid)

Uses existing Redis infrastructure (already configured in prod via vault). Graceful no-op fallback if Redis is unavailable.

Test plan

  • Wait for prod deploy after merge
  • time curl https://nodes-api.desci.com/v1/pub/versions/ZoHA0q5s5hLtzBI1gU8xSUhPSGSDX-aI6pm-dPOrARE. — first call ~5s (cold), subsequent <500ms
  • Verify dpid.org/1077 → nodes.desci.com/dpid/1077 loads in browser <2s
  • (Optional) Run npx ts-node desci-server/src/scripts/warm-versions-cache.ts in a prod pod to pre-warm all dpids

🤖 Generated with Claude Code

hubsmoke and others added 2 commits April 28, 2026 23:57
Root cause: /v1/pub/versions calls dpid.org/api/v2/query/history which
takes 5-8 seconds per request (queries Ceramic for version anchoring).
This blocks every dpid page SSR render.

Fix: wrap getIndexedResearchObjects in getOrCache with 1-day TTL.
- First request: 5-8s (cold, fetches from dpid.org)
- Subsequent requests: <100ms (Redis hit)
- Cache invalidated on publish (delFromCache in publish controller)

Uses existing Redis infrastructure (getOrCache, ONE_DAY_TTL).

Trace data:
  POST dpid.org/api/v2/query/history {ids:["1077"]} = 7.06s TTFB
  GET /v1/pub/versions/{uuid} = 5.27s TTFB (99% is the above call)
  All other SSR steps combined = <500ms

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Queries all published nodes from DB and calls getIndexedResearchObjects
for each, populating the indexed-versions-{uuid} cache keys.

Usage:
  npx ts-node src/scripts/warm-versions-cache.ts
  CONCURRENCY=5 npx ts-node src/scripts/warm-versions-cache.ts

Runs with concurrency=3 by default to avoid overwhelming dpid.org.
Can be run as a one-time migration after deploy, or scheduled as a
daily cron to keep caches warm.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Apr 29, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 533cccb0-c114-407b-a1a2-d45e3b858333

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 hotfix/cache-pub-versions-prod

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

@hubsmoke hubsmoke merged commit d3949ab into main Apr 29, 2026
2 of 3 checks passed
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.

1 participant