Refresh update check on page load when cache is stale - #9
Merged
Merged
Conversation
The daily cron already keeps system.updateCheck fresh, so most page loads just read the cached setting — no outbound request. As a backstop for when the cron missed its run, getUpdateStatus() now schedules one background GitHub check (via next/server's after(), so it doesn't block the response) whenever the cached result is older than 20 hours. Concurrent requests during that window are deduped via an in-memory in-flight guard.
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.
Summary
Follow-up to #5. The daily cron (
check-updatespg-boss job,0 6 * * *) already keepssystem.updateCheckfresh, so most page loads just read the cached setting — no outbound request.As a backstop for when the cron missed its run (e.g. the server was down at 06:00),
getUpdateStatus()now schedules one background GitHub check via Next.js'safter()(runs after the response is sent, doesn't block the page) whenever the cached result is older than 20 hours. Concurrent requests during that window are deduped via an in-process in-flight guard, so several tabs/admins loading a page at once while the cache is stale only trigger one outbound request.Net effect: on login or a full page reload, an admin sees a check that's at most ~20h old, refreshing itself in the background if it's gone stale — without hitting GitHub's API on every request.
Test plan
npx tsc --noEmitnpx eslint src/lib/update-check.tsnpx prettier --check src/lib/update-check.tscheckedAtinsystem.updateCheck, confirm a page load triggers exactly one refresh (check server logs / the setting'scheckedAtupdates)Generated by Claude Code