Skip to content

Resolve "Projects::CompareController#show is calling Gitaly n+1 times per request"

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?

What are the relevant issue numbers?

Closes #37430 (closed)

Edited by Alejandro Rodríguez

Merge request reports

Loading