Resolve "Projects::CompareController#show is calling Gitaly n+1 times per request"
requested to merge 37430-projects-comparecontroller-show-is-calling-gitaly-n-1-times-per-request into master
What does this MR do?
Fix n+1 issue by not reloading fully loaded blobs.
For Projects::CompareController#show
we currently make a Gitlab::Git::Repository#batch_blobs
call to bring all blobs in a single rugged/gitaly call. However, when rendering the view a call to Gitlab::Git::Blob#load_all_data!
is performed for each blob, which generates the n+1 situation. Now, when calling load_all_data!
we first check if the blob is already fully loaded to avoid making a rugged/gitaly call. Notice that individual blobs whose size exceed Gitlab::Git::Blob::MAX_DATA_DISPLAY_SIZE
(10mb) will still need a separate call to load their full size.
Are there points in the code the reviewer needs to double check?
No
Why was this MR needed?
This n+1 issue is preventing gitaly features to be enabled in production gitaly#993 (closed)
Does this MR meet the acceptance criteria?
-
Changelog entry added, if necessary -
Documentation created/updated -
API support added -
Tests added for this feature/bug - Review
-
Has been reviewed by UX -
Has been reviewed by Frontend -
Has been reviewed by Backend -
Has been reviewed by Database
-
-
Conform by the merge request performance guides -
Conform by the style guides -
Squashed related commits together -
Internationalization required/considered -
End-to-end tests pass ( package-qa
manual pipeline job)
What are the relevant issue numbers?
Closes #37430 (closed)
Edited by Alejandro Rodríguez