Add ETag conditional-request cache to cut GitHub API usage#468
Closed
ianrohde wants to merge 1 commit into
Closed
Conversation
On boot, refresh.openPulls() re-fetches every open pull (~8-15 REST calls each) even though almost none changed since the last run, which can drain the hourly quota and take the app down (#467). A conditional request returning 304 Not Modified does not count against the primary rate limit. installEtagCache wraps the Octokit request hook to remember each GET's ETag and replay it via If-None-Match, so unchanged resources cost no quota. Bounded LRU keyed by resolved method+url (paginated pages key separately). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
Author
|
I don't think this is necessary |
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.
Draft for option 1 in #467.
What
Adds an in-process ETag conditional-request cache to the Octokit client. A conditional request returning
304 Not Modifieddoes not count against the primary REST rate limit (docs).lib/etag-cache.jswraps the Octokitrequesthook to:ETag,If-None-Matchon the next identical request,304.Why
On boot,
app.jsrunsrefresh.openPulls(), sending every open pull (across all repos) throughgit-manager.parse()— ~8–15 REST calls each. Almost none have changed since the last run, so on a restart this re-fetch is mostly wasted quota and can blow the 5000/hr limit (the incident in #467). With the cache, unchanged resources return304and cost nothing.How
installEtagCache(octokit)is called once ingit-manager.js, right after the client is built (composes with the existing throttling plugin).Mapused as a rough LRU (default 2000 entries), keyed by the resolvedmethod + urlso paginated pages cache separately.Test plan
node --test test/*.test.js— newtest/etag-cache.test.jsdrives a real Octokit with a stubfetch, asserting the 200→304 replay path and that the cachedETagis sent viaIf-None-Match; non-GETs send no conditional header.npx eslinton changed files — clean.304s (debugpulldasher:etag-cache) and thatcorerate-limit usage drops vs. a cold start.Notes / open questions for #467
maxEntriesdefault 2000 is a guess; size to open-pull count × endpoints-per-pull.getAllJobRuns(Reduce GitHub API consumption to avoid rate-limit outages #467 item 2) — that's the next lever.