Support batch loading of merge head diffs
What does this MR do?
Re-use MergeRequestDiff
model and tables with additional diff_type
enum attribute. This is to identify that the MR diff is a merge head diff or a regular one.
This allow us to use the batch diffs performance improvements and sorting capability implemented in #26552 (closed).
Migration
== 20210107105306 AddDiffTypeToMergeRequestDiffs: migrating ===================
-- column_exists?(:merge_request_diffs, :diff_type)
-> 0.0017s
-- add_column(:merge_request_diffs, :diff_type, :integer, {:null=>false, :limit=>2, :default=>1})
-> 0.0013s
-- transaction_open?()
-> 0.0000s
-- index_exists?(:merge_request_diffs, :merge_request_id, {:unique=>true, :where=>"diff_type = 2", :name=>"index_merge_request_diffs_on_unique_merge_request_id", :algorithm=>:concurrently})
-> 0.0027s
-- execute("SET statement_timeout TO 0")
-> 0.0002s
-- add_index(:merge_request_diffs, :merge_request_id, {:unique=>true, :where=>"diff_type = 2", :name=>"index_merge_request_diffs_on_unique_merge_request_id", :algorithm=>:concurrently})
-> 0.0065s
-- execute("RESET ALL")
-> 0.0002s
== 20210107105306 AddDiffTypeToMergeRequestDiffs: migrated (0.0172s) ==========
Queries
Tested locally with a merge request with 1000 regular
merge request diffs and single merge_head
diff.
SELECT "merge_request_diffs".* FROM "merge_request_diffs" WHERE "merge_request_diffs"."merge_request_id" = 3695 AND "merge_request_diffs"."diff_type" = 1
Plan: https://explain.depesz.com/s/ngoA
SELECT "merge_request_diffs".* FROM "merge_request_diffs" WHERE "merge_request_diffs"."merge_request_id" = 3695 AND "merge_request_diffs"."diff_type" = 2
Plan: https://explain.depesz.com/s/LVnB
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 #292507 (closed)
Edited by Patrick Bajao