Skip to content

fix: use cached specialPosts promise in SSR to reduce CPU usage#3973

Merged
kuny0707 merged 1 commit intomasterfrom
fix/special-posts-cache
Apr 3, 2026
Merged

fix: use cached specialPosts promise in SSR to reduce CPU usage#3973
kuny0707 merged 1 commit intomasterfrom
fix/special-posts-cache

Conversation

@ety001
Copy link
Copy Markdown
Member

@ety001 ety001 commented Apr 2, 2026

Summary

  • app_render.jsx was calling specialPosts() directly on every SSR request, bypassing the cached promise (app.specialPostsPromise) that refreshes every 5 minutes in server.js
  • Each specialPosts() call triggers 10+ sequential HTTP requests to the blockchain API (one per featured/promoted post + notices), causing CPU saturation during traffic peaks (2-3 hour daily spikes at 85%+ CPU)
  • Fix: Pass the cached promise through Koa middleware (ctx.specialPostsPromise) and use it in app_render.jsx instead of calling specialPosts() directly

Changes

  • src/server/server.js: Added middleware to pass app.specialPostsPromise to request context
  • src/server/app_render.jsx: Replaced await specialPosts(ctx.session.uid) with await ctx.specialPostsPromise, removed unused import

Test plan

  • Deploy and monitor Loading special posts log frequency — should appear every 5 minutes only (not per request)
  • Monitor CPU usage via top/htop during peak hours — should see significant reduction
  • Verify special posts still render correctly on the homepage

…r request

The specialPosts() function was being called directly on every SSR request
in app_render.jsx, bypassing the cached promise (refreshed every 5 minutes)
set up in server.js. Each call triggered 10+ sequential HTTP requests to
the blockchain API, causing CPU saturation during traffic peaks.
@kuny0707 kuny0707 merged commit ddad34f into master Apr 3, 2026
1 check 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.

2 participants