Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Provaznik <jprovaznik@gitlab.com>2017-12-29 19:15:50 +0300
committerJan Provaznik <jprovaznik@gitlab.com>2018-01-10 22:40:02 +0300
commite6a1db6d9e3036ae0c9dc677f9029f5acf37f9f6 (patch)
tree2ba714a0042a675af0cb0b604f46b927409a628c /db/migrate/20180105212544_add_commits_count_to_merge_request_diff.rb
parent047cde243ed0fb0e71ddf85735342bec66c92eae (diff)
Denormalize commits count for merge request diffs
For each MR diff an extra 'SELECT COUNT()' is executed to get number of commits for the diff. Overall time to get counts for all MR diffs may be quite expensive. To speed up loading of MR info, information about number of commits is stored in a MR diff's extra column. Closes #38068
Diffstat (limited to 'db/migrate/20180105212544_add_commits_count_to_merge_request_diff.rb')
-rw-r--r--db/migrate/20180105212544_add_commits_count_to_merge_request_diff.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/db/migrate/20180105212544_add_commits_count_to_merge_request_diff.rb b/db/migrate/20180105212544_add_commits_count_to_merge_request_diff.rb
new file mode 100644
index 00000000000..f942b4c062e
--- /dev/null
+++ b/db/migrate/20180105212544_add_commits_count_to_merge_request_diff.rb
@@ -0,0 +1,29 @@
+class AddCommitsCountToMergeRequestDiff < ActiveRecord::Migration
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ MIGRATION = 'AddMergeRequestDiffCommitsCount'.freeze
+ BATCH_SIZE = 5000
+ DELAY_INTERVAL = 5.minutes.to_i
+
+ class MergeRequestDiff < ActiveRecord::Base
+ self.table_name = 'merge_request_diffs'
+
+ include ::EachBatch
+ end
+
+ disable_ddl_transaction!
+
+ def up
+ add_column :merge_request_diffs, :commits_count, :integer
+
+ say 'Populating the MergeRequestDiff `commits_count`'
+
+ queue_background_migration_jobs_by_range_at_intervals(MergeRequestDiff, MIGRATION, DELAY_INTERVAL, batch_size: BATCH_SIZE)
+ end
+
+ def down
+ remove_column :merge_request_diffs, :commits_count
+ end
+end