Skip to content

Improve performance of MR changes count

Patrick Bajao requested to merge 381438-improve-mr-changes-count into master

What does this MR do and why?

Before this change, when we display a merge request with lots of commits, it can take around 30% of the time to display the MR overview page. This is because we load all the MR commits when we call DiffHelper#show_only_context_commits?.

With this fix, we avoid loading all MR commits when checking if we need to show context commits or not by utilizing the MergeRequest#has_no_commits? method that will internally check the MergeRequestDiff#commits_count (a cache column in merge_request_diffs).

Duration of Projects::MergeRequestsController#show locally:

  • Before: ~1.2s
  • After: ~0.9s

Shows ~33% improvement.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #381438 (closed)

Merge request reports

Loading