Optimize caching, polling, and retry strategies for performance#759
Conversation
Reduce origin (Cloud Run) request load that was driving the ~9x request spike: - Update-version checker (app layout): was fetching the full current page with `no-store` every 60s on every signed-in tab, forever. Now polls ~every 15 min, only while the tab is visible, with jitter so clients don't poll in lockstep, and stops once an update is detected. This was the single biggest driver of both the request spike and uncached CDN bandwidth. - Market page: the 60s refresh is a Server Action hitting the origin; throttled to 5 min (underlying market data revalidates on 60s+ anyway). - BTC price ticker: throttled from 60s to 5 min. - Wallet error-retry: replaced the fixed 3s retry with exponential backoff (3s/6s/12s, capped at 60s) and debounced the on-focus retry so a focus storm can't fire back-to-back origin calls. https://claude.ai/code/session_01PAJeRubmNYpCjy1PvvyfgJ
Address the Firebase App Hosting CDN cache-miss rate (uncached origin bandwidth jumped 52 GiB -> 726 GiB). App Hosting only edge-caches responses whose origin emits a cacheable Cache-Control header, and almost nothing did. next.config.ts headers(): - /public static assets (svg/png/jpg/webp/ico/woff/woff2): 1 week + SWR. - manifest.json: 1 day. - /landing and /about (public marketing pages): s-maxage 1h + SWR. - Signed-in app shells (dashboard, analysis, security, chat, report, coin-control): s-maxage 5m + SWR. These render an identical shell per user — wallet data loads client-side via Server Actions and auth gating is client-side — so only the static shell is cached; per-user data requests are separate POSTs that always reach the origin. Parameterised routes (address/[address] etc.) and /api/* are intentionally excluded. Also: - /landing and /about: add `revalidate = 3600` (ISR) to back the headers. - sitemap: use a stable lastModified instead of `new Date()` so it stops appearing "always new" to crawlers on every build. https://claude.ai/code/session_01PAJeRubmNYpCjy1PvvyfgJ
|
@claude can you code review the pr 759 and make any changes required |
Code-review follow-up. In the version-update checker, if the `fetch(window.location.href)` is still in flight when the effect is cleaned up (component unmounted), the resolved callback could call `setIsUpdateAvailable` on an unmounted component. The cleanup already sets the shared `stopped` flag, so check it before the state update. https://claude.ai/code/session_01PAJeRubmNYpCjy1PvvyfgJ
Code review — PR #759Reviewed the full diff (caching headers + polling/backoff changes) at high effort, verifying the riskiest parts (Next.js header source-pattern matching and the rewritten timer/retry logic) with focused checks. No correctness bugs found. Details:
One minor fix applied ( Everything else is good to go. The one thing worth a human eye before merge is the intended-but-sensitive change: signed-in app shells ( Generated by Claude Code |
Summary
This PR implements comprehensive performance optimizations across caching, polling intervals, and retry logic to reduce unnecessary origin requests and improve user experience.
Key changes:
LAST_MODIFIEDtimestamp to prevent crawlers from seeing the sitemap as "always new"revalidate = 3600to landing and about pages for ISR-based edge cachingType of Change
Test Plan
next.config.tsChecklist
npm run typecheckpassesnpm run lintpassesnpm run testpasseshttps://claude.ai/code/session_01PAJeRubmNYpCjy1PvvyfgJ