diff options
author | Jan Provaznik <jprovaznik@gitlab.com> | 2017-12-29 17:15:50 +0100 |
---|---|---|
committer | Jan Provaznik <jprovaznik@gitlab.com> | 2018-01-10 20:40:02 +0100 |
commit | e6a1db6d9e3036ae0c9dc677f9029f5acf37f9f6 (patch) | |
tree | 2ba714a0042a675af0cb0b604f46b927409a628c /db | |
parent | 047cde243ed0fb0e71ddf85735342bec66c92eae (diff) | |
download | gitlab-ce-e6a1db6d9e3036ae0c9dc677f9029f5acf37f9f6.tar.gz |
Denormalize commits count for merge request diffs38068-commits-count
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')
-rw-r--r-- | db/migrate/20180105212544_add_commits_count_to_merge_request_diff.rb | 29 | ||||
-rw-r--r-- | db/schema.rb | 3 |
2 files changed, 31 insertions, 1 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 diff --git a/db/schema.rb b/db/schema.rb index a16f756ccfb..07620349057 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20171230123729) do +ActiveRecord::Schema.define(version: 20180105212544) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -1044,6 +1044,7 @@ ActiveRecord::Schema.define(version: 20171230123729) do t.string "real_size" t.string "head_commit_sha" t.string "start_commit_sha" + t.integer "commits_count" end add_index "merge_request_diffs", ["merge_request_id", "id"], name: "index_merge_request_diffs_on_merge_request_id_and_id", using: :btree |