Build the diff collection once in the Code Review Analytics API

What does this MR do and why?

Related to https://gitlab.com/gitlab-org/gitlab/-/work_items/636159

GET /api/v4/analytics/code_review builds diff_stats for each merge request by calling object.diffs.diff_files twice, once for additions and once for deletions. Each MergeRequest#diffs call builds a new Gitlab::Diff::FileCollection::MergeRequestDiff, so every merge request decorated its diff files twice and read the highlight cache and the diff stats cache twice.

This MR builds the collection once. The output is unchanged.

This is the first of two MRs for the issue's "make each MR cheaper" step. The next one, behind a feature flag, drops the merge_request_diff_files preload: !268231 (merged)

No feature flag: the change only removes a duplicate call.

How to set up and validate locally

bundle exec rspec ee/spec/lib/api/entities/analytics/code_review/merge_request_spec.rb \
  ee/spec/requests/api/analytics/code_review_analytics_spec.rb

The existing diff_stats expectation (118 / 9 / 127 / 29) still passes. The new example checks that diffs is called once. It fails without the change (received 2 times).

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist.

Edited by Jatin Parihar

Merge request reports

Loading
Loading