Skip to content

Sort merge request diff files directory first

Patrick Bajao requested to merge 26552-sort-diff-files into master

What does this MR do?

Each file browser and the diffs we show under the "Changes" tab need to be consistent to prevent confusion.

Whenever we create a merge request diff, we create and store MergeRequestDiffFile records and we keep the relative_order of each file.

In order for the new sorting order to persist, we will sort the diff files on:

  • when a MergeRequestDiff is created
  • when we load merge request diffs

Then we persist/update the relative_order of each file. A sorted boolean column has been added to merge_request_diffs table to determine if we need to reorder diff files.

This is behind a feature flag called sort_diffs which is disabled by default.

This does not affect when viewing MR diffs when whitespace is ignored or when viewing MR diffs for a specific commit yet. It'll be handled in a separate MR: !49136 (merged).

Queries

For MergeRequestDiff#reorder_diff_files!:

Benchmark

I had an MR with 10,000 files (it gets limited to 1K diff files) and here are the results:

  • MergeRequestDiff#reorder_diff_files! takes ~130ms
  • MergeRequestDiff#sort_diffs takes ~10ms

Migration

== 20201202133606 AddSortedToMergeRequestDiffs: migrating =====================
-- add_column(:merge_request_diffs, :sorted, :boolean, {:null=>false, :default=>false})
   -> 0.0045s
== 20201202133606 AddSortedToMergeRequestDiffs: migrated (0.0046s) ============

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • [-] Label as security and @ mention @gitlab-com/gl-security/appsec
  • [-] The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • [-] Security reports checked/validated by a reviewer from the AppSec team

Related to #26552 (closed)

Edited by Patrick Bajao

Merge request reports