Skip to content

Cache the GHES instance check across organizations - #298

Draft
john7doe wants to merge 1 commit into
mainfrom
memoize-enterprise-check
Draft

Cache the GHES instance check across organizations#298
john7doe wants to merge 1 commit into
mainfrom
memoize-enterprise-check

Conversation

@john7doe

Copy link
Copy Markdown

What this does

Caches the GHES instance check so it costs one API request per instance instead of one per organization.

pending_members calls enterprise? before it does anything else, and enterprise? queried the meta endpoint every single time with no caching. Since pending_members is 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.

Component Time
Fixed, 0.82s per org 136s
Pagination, 23ms per pending member 226s

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_signature would keep the request count at one per org and defeat the point.

The cache is read with key? rather than ||=. false is 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.

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
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