Sort merge request diff files directory first
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!
:
-
DELETE
: https://explain.depesz.com/s/CPieH -
INSERT
(2 batches, 500 each): https://explain.depesz.com/s/QDui -
UPDATE
: https://explain.depesz.com/s/K5aG
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
-
Changelog entry - [-] Documentation (if required)
-
Code review guidelines -
Merge request performance guidelines -
Style guides -
Database guides - [-] Separation of EE specific content
Availability and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process. - [-] Tested in all supported browsers
- [-] Informed Infrastructure department of a default or new setting change, if applicable per definition of done
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)