Cache the GHES instance check across organizations - #298
Draft
john7doe wants to merge 1 commit into
Draft
Conversation
enterprise? queried the meta endpoint on every call, and pending_members calls it once per organization. Whether an instance is GHES cannot vary between orgs on that instance, so this was one request per org for a constant answer. Caches against the address rather than the org signature. Checks for the key rather than using ||= because false is a valid cached answer, and is the answer github.com gives. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: d95a67cd-ec62-497a-99fc-cf447ee1d49b
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.
What this does
Caches the GHES instance check so it costs one API request per instance instead of one per organization.
pending_memberscallsenterprise?before it does anything else, andenterprise?queried the meta endpoint every single time with no caching. Sincepending_membersis memoized per organization, that worked out to one meta request per org, for an answer that cannot vary between orgs on the same instance.Measured on a run covering 165 organizations, the pending member lookups cost 362s in total. Regressing that against the number of pending members in each org splits it into a fixed cost and a pagination cost.
The 124 orgs that have no pending members at all still cost 0.86s each, and in that case the work is exactly two API requests, the meta check and one empty page. So the meta check is roughly half the fixed cost, and removing it should save somewhere around 70s on a run of that size. That last step assumes the two requests have similar latency, so treat it as an estimate rather than a measurement.
How
enterprise?now caches against the address rather than the org signature. GHES-ness is a property of the instance, so the address is the correct key.org_signaturewould keep the request count at one per org and defeat the point.The cache is read with
key?rather than||=.falseis a valid answer here and the one github.com gives, so||=would treat every cached result as a miss and change nothing.One spec covers it, asserting the meta endpoint is requested once across two service objects for different orgs on the same instance. Without the change it is requested twice.
Notes
This is independent of #297 and the two can land in either order. This one stands alone and does not depend on
max_parallelism.Full suite passes with 100 percent coverage and RuboCop is clean.