Prefetch organization pending members - #297
Draft
john7doe wants to merge 1 commit into
Draft
Conversation
Moves the pending member lookup into prefetch, which runs through a thread pool sized by max_parallelism, instead of calculate, which runs serially. The result is memoized so the API request count is unchanged. 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
Moves the organization pending member lookup into
prefetch, which entitlements runs through a thread pool, instead of leaving it incalculate, which runs serially.On a no-op deploy across a large set of organizations, that one call accounts for roughly half of the entire run.
calculateprefetchandvalidatemax_parallelismThe lookups are not redundant, so caching does not help. Each one is a different organization returning a different result, and every second of that 341s is time spent waiting on the API. The only way to shorten it is to let the requests overlap, and
prefetchis already the phase built to do that.How
GitHubOrg::Controller#prefetchnow callsprovider.pending_membersalongsideexisting_groups. The result is memoized inEntitlements.cache[:github_pending_members], sochangesreuses it later incalculaterather than issuing the request itself. The number of API requests is unchanged. Only the phase they happen in moves.Three controller specs gained a
pending_membersstub on their providerinstance_double, since those examples callprefetchdirectly. One strict call count went from two to three, because that example stubs the service rather than the provider and so bypasses the memoization that keeps the real request count flat.GitHubTeam::Controlleris left alone. Itsprefetchalready warms the provider reads that itscalculateconsumes.Notes
This pays off only when
max_parallelismis greater than 1. At the default of 1 theprefetchpool is serial as well, so the work still moves out ofcalculatebut the wall time stays the same. Nothing regresses in that case, which makes this safe to land ahead of any consumer raising the value.Full suite passes with 100 percent coverage and RuboCop is clean.