Set limits for Projects::CompareController#show
What does this MR do and why?
The issue: https://gitlab.com/gitlab-org/gitlab/-/issues/550847+
This MR optimizes the compare page performance by preventing unnecessary pipeline queries when there are too many commits to display pipeline status.
Problem
Currently, the compare page always executes expensive pipeline queries (with_latest_pipeline) regardless of whether the pipeline status will be displayed in the UI. When there are many commits (above MergeRequestDiff::COMMITS_SAFE_SIZE), GitLab hides the pipeline status indicators but still runs the database queries to fetch pipeline data, resulting in wasted resources.
| with few commits | with many commits |
|---|---|
![]() |
![]() |
Solution
Add a conditional check to only fetch pipeline information when the number of commits is below the safe display limit. This prevents expensive pipeline queries when the results won't be shown to users, improving page load performance for comparisons with many commits.
How to test
-
if the project has no
.gitlab-ci.ymlfile, you should create a new one, for exampletest: script: - echo hello world -
create a new brach with a few commits
-
you can adjust
MergeRequestDiff::Commits_safe_sizefor testing -
with the total number of commits < threshold: check your performance bar. You should see sql queries for
p_ci_pipelines -
with the total number of commits > threshold: check your performance bar. There shouldn't be sql queries for
p_ci_pipelines
Screenshots or screen recordings
note: I adjusted MergeRequestDiff::Commits_safe_size = 1 for the many commits case.
| the compare page | the performance bar sql queries | |
|---|---|---|
|
3 commits < commits_safe_size(100) |
||
|
3 commits > commits_safe_size(1) |
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.





