Skip to content

Support batch loading of merge head diffs

Patrick Bajao requested to merge 292507-batch-merge-ref-diff into master

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

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 #292507 (closed)

Edited by Patrick Bajao

Merge request reports