Repository navigation
fix(index): stop blocking page render on the modarchive RSS feed - #209
Merged
Merged
Conversation
getServerSideProps awaited modarchive.org/rss.php on every request to find the newest module id. The feed takes 2.5 to 4 s to answer, so the start page TTFB was about 3 s for every visitor. Move the lookup into lib/modarchive/latest-id.ts. getLatestId() returns the cached id, or RANDOM_MAX before the first fetch lands, and starts one background refresh when the value is older than an hour. A failed or timed-out (10 s) fetch keeps the previous value. Local production build: TTFB 45 ms on the first request, 4 ms after. Closes #208 Assisted-by: ClaudeCode:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GwowRkcBNzHsDGBXywedzR Signed-off-by: Ronny Trommer <ronny@no42.org>
- Clear the in-flight promise via .finally() in getLatestId, so a synchronous throw inside fetch can no longer leave a settled promise in `refreshing` and block every later refresh. - Retry a failed fetch after one minute instead of a full hour, so a cold-start failure does not pin visitors to RANDOM_MAX. - Reuse fetchHtml (project User-Agent, throws on non-2xx) with a new optional AbortSignal parameter instead of a bare fetch. - Document the long-lived server process assumption. - Tests for non-2xx, retry after failure, and synchronous throw. Refs #208 Assisted-by: ClaudeCode:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GwowRkcBNzHsDGBXywedzR Signed-off-by: Ronny Trommer <ronny@no42.org>
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.
Closes #208
What
The start page's
getServerSidePropsawaitedhttps://modarchive.org/rss.php?request=uploadson every request. It only needed the newest module id, which is the upper bound for random picks. That feed takes 2.5 to 4 s to answer, so every visitor waited that long for the first byte.lib/modarchive/latest-id.ts:getLatestId(fallback)returns the cached id right away, or the fallback before the first fetch lands. A value older than one hour triggers one background refresh. The refresh times out after 10 s. A failed fetch keeps the last good value.pages/index.tsxcallsgetLatestId(RANDOM_MAX)instead of the blocking fetch. The file also gets its missing SPDX header.lib/modarchive/latest-id.test.tscovers the fallback, caching, single in-flight refresh, failure, and TTL expiry.Trade-off
For the first seconds after a server restart, pages get
RANDOM_MAX(190580). The old code already used that value whenever the fetch failed. During that window random picks can't land on the newest uploads.Verification
make verifypasses (lint, typecheck, unit tests, audit, build).next start, four requests to/3 s apart:Production before this change: 2.65 s, 2.73 s, 4.05 s TTFB.
馃 Generated with Claude Code
https://claude.ai/code/session_01GwowRkcBNzHsDGBXywedzR