Repository navigation
feat(github): conditional requests so unchanged reads cost no rate limit - #59
Merged
Merged
Conversation
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.
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.