Skip to content

feat(github): conditional requests so unchanged reads cost no rate limit - #59

Merged
JustMaris merged 1 commit into
mainfrom
perf/conditional-requests
Nov 19, 2026
Merged

JustMaris merged 1 commit into
mainfrom
perf/conditional-requests

Conversation

@JustMaris

Copy link
Copy Markdown
Member

Each GET's last 200 (body, ETag, Link) is kept in memory and the next request to the same URL sends If-None-Match. GitHub answers 304 without counting it against the rate limit, and the client hands the cached 200 back, so callers do not change. The repo list, per-repo workflows, Dependabot alerts and PR counts rarely change, so after the first poll they cost close to nothing; the same URL read by two collectors (orgstats and adoption both read open PR counts) is free the second time. Bodies over 2 MiB and more than 4096 URLs are not cached. New metric github_api_requests_total{result="fresh|not_modified"} to see the saving.

Measured before: about 600 calls in half an hour (roughly a quarter of the 5000/h budget) with ~40 repos polled every 5 min.

Tests: a 304 returns the cached body with its Link header intact (OpenPRCount reads the "last" rel), If-None-Match is sent from the second request, rate-limit headers are still recorded on a 304, counts, and an oversized body is read but not cached.

@JustMaris
JustMaris merged commit 3d137e4 into main Nov 19, 2026
8 checks passed
@JustMaris
JustMaris deleted the perf/conditional-requests branch November 19, 2026 11:49
@dnb-robot dnb-robot Bot mentioned this pull request Nov 19, 2026
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