perf: cache /v1/pub/versions in Redis (cherry-pick #1281 to prod)#1285
Merged
Conversation
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>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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)
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— wrapsgetIndexedResearchObjectsingetOrCachewith 1-day TTLdesci-server/src/controllers/nodes/publish.ts— invalidatesindexed-versions-{uuid}cache on publishdesci-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
time curl https://nodes-api.desci.com/v1/pub/versions/ZoHA0q5s5hLtzBI1gU8xSUhPSGSDX-aI6pm-dPOrARE.— first call ~5s (cold), subsequent <500msnpx ts-node desci-server/src/scripts/warm-versions-cache.tsin a prod pod to pre-warm all dpids🤖 Generated with Claude Code