Skip to content

reduce response times, improve caching #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 83 commits into
base: readme-test
Choose a base branch
from
Draft

Conversation

martin-mfg
Copy link
Owner

This PR improves caching and refreshing of generated statistics and thereby reduces server response time.

Proactive refreshing of statistics

Add a database which stores all incoming requests of the past 8 days. The server periodically re-computes and pre-caches the data for all these requests so it can quickly serve fresh data from cache on incoming user requests.

Use Vercel's "Incremental Static Regeneration" feature

This is an additional caching layer to reduce load on the backend. One notable feature is that the ISR cache can serve old cached data while it requests fresh data from the server in the background. So responses feel immediate to the user.

Shorter cache times to serve more recent data

Since the new caching functionalities will reduce server load, the server should be able to refresh data more often. So I shortened cache durations. The current timings are:

  • all normal endpoints set a cache duration of 10 hours
  • the ISR layer caches these endpoints' data for 11 hours
  • the /status/up and /status/pat-info endpoints set a cache duration of 3 minutes
  • a cron job triggers re-computation of recent requests every 1 hour (but GitHub might occasionally delay or skip triggers)
  • during re-computation, all requests which are between 11 hours and 8 days old will be re-computed (and requests older than 8 days will be deleted)

Supporting changes

  • add a new endpoint /api/repeat-recent to trigger re-computation
  • add a GitHub action with a cron trigger which calls this endpoint
  • use Vercel's Build Output API to define Incremental Static Regeneration functions
  • for this to work, there must not be an /api directory, so I renamed it to /api-renamed
  • I also had to add a router.js as common entrypoint and to provide express.js-like request and response objects
  • make the whole database functionality of storing requests and re-computing statistics optional, depending on if the environment variable POSTGRES_URL is set
  • removed the maxDuration setting of 10 seconds, so the default value should now be 60 seconds

Copy link

vercel bot commented Jun 29, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
github-readme-stats ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 29, 2025 11:58am

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.

1 participant