perf(sponsor): render wall statically with on-demand revalidation - #54
Conversation
The /sponsor page was force-dynamic, so every visit paid a full SSR: two DB reads (SponsorHero + SponsorWall each call getPublicSponsors) plus a fresh render of the whole tree. The sponsor list only changes on admin edits, so the per-request DB query + render was wasted Vercel Active CPU — the same class of cost #53 cut for the rest of the [locale] subtree. Switch to the repo's established static + tag-based revalidation pattern (mirrors articles / use-cases): - sponsors-store: wrap getPublicSponsors in unstable_cache under a new SPONSORS_PUBLIC_CACHE_TAG. Also dedupes the hero + wall reads in a single render into one DB query. - sponsor/page: drop force-dynamic for `revalidate = 1800`. The layout's generateStaticParams + setRequestLocale already make the subtree static (no cookies/headers), so the page now serves from cache. The 30-min ISR window is just a safety net. - admin sponsor routes (create / update / delete / reorder): call revalidateTag(SPONSORS_PUBLIC_CACHE_TAG) so the wall rebuilds on demand. Self-service claim links need no revalidation: they create `pending` rows that only reach the wall after an admin publish (the PATCH route above).
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughThe public sponsors list is now served from a Next.js Sponsor Wall ISR Caching
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration. 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. Comment |
问题
/sponsor页面之前是force-dynamic,每次访问都做完整 SSR:SponsorHero和SponsorWall各调一次getPublicSponsors)赞助名单只在后台 admin 操作时才变,绝大多数访问都在做无意义的 DB 查询 + 渲染——正是 #53 想砍掉的那类 Vercel Active CPU 消耗。
方案
套用仓库里已有的「静态渲染 + cache tag 按需失效」模式(与 articles / use-cases 一致):
sponsors-store:用unstable_cache包裹getPublicSponsors,打上新增的SPONSORS_PUBLIC_CACHE_TAG。附带把 hero + wall 同一次渲染里的两次读取去重成一次 DB 查询。sponsor/page:删除force-dynamic,改为revalidate = 1800。layout 的generateStaticParams+setRequestLocale已让子树静态化(无 cookies/headers 依赖),页面现在从缓存直出;30 分钟 ISR 仅作兜底。revalidateTag(SPONSORS_PUBLIC_CACHE_TAG),赞助墙按需重建。self-service 邀请链接 claim 路由无需失效:它创建的是
pending行,要等 admin 审核 publish(走上面的 PATCH 路由)后才上墙。效果
赞助页从「每次访问 SSR + 2 次 DB 查询」变为「CDN 缓存直出,仅 admin 改动时重建」。部署后可在构建路由表确认
/sponsor从ƒ (Dynamic)变为● (ISR)。验证
bun run typecheck✅eslint(改动文件)✅Summary by CodeRabbit
New Features
Bug Fixes