feat: add a simple in-memory cache for suborg/repo config fetches#817
Merged
Merged
Conversation
|
fixes #816 |
|
probably fixes #559 |
|
@decyjphr, we have tested this with our fork of safe-settings and have been running it in production now for a few weeks without any issues. what else can we do to help get this merged? |
zpratt
approved these changes
May 6, 2025
Collaborator
|
Zach, will merge soon. Travel got in the way. |
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.
Fixes #816
This PR adds a simple in-memory cache in the
loadYamlfunction, that stores the response + etag of calls to thegetContentcall. Then, future calls are made with theIf-None-Matchheader set to that etag, so that we can optimistically just return from the cache instead and save ourselves the api call. In our instance of safe settings, this ends up saving about 96% of our api calls for our app. (We've made 3.4M api calls in the last week, of which 3.248M were cached - about 95.5%)Because safe settings attempts to load all of the repo configs & suborg configs every time a sync is done, that api call usage tends to grow explosively on large orgs. We run this in an org with around 8500 repos in it, and because we have 140-ish suborgs, that ends up being 140 suborg calls against our api limit every time a setting is changed!
With this change, we store the response of each of those calls in memory, and only make an api call if github knows the file contents have changed.
This is a VERY simple cache, so it has some limitations: