This repository has been archived by the owner on Sep 30, 2024. It is now read-only.
Perf: optimize fetching last file commit #58055
Merged
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.
When fetching the information about the commit that modified a file, we use an
ancestors
query that is filtered to the file name. This is a paginated interface, so we always request n+1 items so we know whether there is a next page.However, the extra requested commit can actually be quite expensive to fetch, particularly in the relatively common case that a file has only been modified in one commit: the one that created it. In that case, we have to iterate over the entire history of the repository to look for a commit that doesn't exist to produce information about a next page that will never be fetched.
The ideal solution here would be to only fetch n+1 if the
hasNextPage
field of the resolver is requested. Unfortunately, our GraphQL package still doesn't support querying for which fields are requested, which is a huge bummer.Instead, this takes a slightly hackier approach and assumes that if the number requested is 1, it's better to serve that quickly and claim we have a next page without knowing whether that page will contain anything.
Test plan
Manually tested the the trace of the
FetchOwnersAndHistory
GraphQL request. For a file with only one commit, the span representing the git command shrunk from 300ms to 70ms, and there no longer a visible loading indicator.