diff options
author | Douwe Maan <douwe@gitlab.com> | 2018-07-03 15:46:23 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2018-07-03 15:46:23 +0000 |
commit | f3e95aae7abb68f86fc614d70d0ec4b9683b7bfb (patch) | |
tree | 8df1a102872fda5e4d9f651e5482f397ab92ca50 /db | |
parent | f30089075fabfbac45c6382c0a2717bbb682734e (diff) | |
parent | acc6e3a0fdb8f710d77b8faa2a39823f7e1c7e5d (diff) | |
download | gitlab-ce-f3e95aae7abb68f86fc614d70d0ec4b9683b7bfb.tar.gz |
Merge branch 'master' into 'web-hooks-log-pagination'
# Conflicts:
# db/schema.rb
Diffstat (limited to 'db')
4 files changed, 22 insertions, 97 deletions
diff --git a/db/fixtures/development/20_nested_groups.rb b/db/fixtures/development/20_nested_groups.rb index 2bc78e120a5..3d95e243f8a 100644 --- a/db/fixtures/development/20_nested_groups.rb +++ b/db/fixtures/development/20_nested_groups.rb @@ -1,30 +1,5 @@ require './spec/support/sidekiq' -def create_group_with_parents(user, full_path) - parent_path = nil - group = nil - - until full_path.blank? - path, _, full_path = full_path.partition('/') - - if parent_path - parent = Group.find_by_full_path(parent_path) - - parent_path += '/' - parent_path += path - - group = Groups::CreateService.new(user, path: path, parent_id: parent.id).execute - else - parent_path = path - - group = Group.find_by_full_path(parent_path) || - Groups::CreateService.new(user, path: path).execute - end - end - - group -end - Sidekiq::Testing.inline! do Gitlab::Seeder.quiet do flag = 'SEED_NESTED_GROUPS' @@ -48,7 +23,8 @@ Sidekiq::Testing.inline! do full_path = url.sub('https://android.googlesource.com/', '') full_path = full_path.sub(/\.git\z/, '') full_path, _, project_path = full_path.rpartition('/') - group = Group.find_by_full_path(full_path) || create_group_with_parents(user, full_path) + group = Group.find_by_full_path(full_path) || + Groups::NestedCreateService.new(user, group_path: full_path).execute params = { import_url: url, diff --git a/db/post_migrate/20180619121030_enqueue_delete_diff_files_workers.rb b/db/post_migrate/20180619121030_enqueue_delete_diff_files_workers.rb deleted file mode 100644 index 5fb3d545624..00000000000 --- a/db/post_migrate/20180619121030_enqueue_delete_diff_files_workers.rb +++ /dev/null @@ -1,70 +0,0 @@ -class EnqueueDeleteDiffFilesWorkers < ActiveRecord::Migration - include Gitlab::Database::MigrationHelpers - - class MergeRequestDiff < ActiveRecord::Base - self.table_name = 'merge_request_diffs' - - belongs_to :merge_request - - include EachBatch - end - - DOWNTIME = false - BATCH_SIZE = 1000 - MIGRATION = 'DeleteDiffFiles' - DELAY_INTERVAL = 8.minutes - TMP_INDEX = 'tmp_partial_diff_id_with_files_index'.freeze - - disable_ddl_transaction! - - def up - # We add temporary index, to make iteration over batches more performant. - # Conditional here is to avoid the need of doing that in a separate - # migration file to make this operation idempotent. - # - unless index_exists_by_name?(:merge_request_diffs, TMP_INDEX) - add_concurrent_index(:merge_request_diffs, :id, where: "(state NOT IN ('without_files', 'empty'))", name: TMP_INDEX) - end - - - diffs_with_files = MergeRequestDiff.where.not(state: ['without_files', 'empty']) - - # explain (analyze, buffers) example for the iteration: - # - # Index Only Scan using tmp_index_20013 on merge_request_diffs (cost=0.43..1630.19 rows=60567 width=4) (actual time=0.047..9.572 rows=56976 loops=1) - # Index Cond: ((id >= 764586) AND (id < 835298)) - # Heap Fetches: 8 - # Buffers: shared hit=18188 - # Planning time: 0.752 ms - # Execution time: 12.430 ms - # - diffs_with_files.each_batch(of: BATCH_SIZE) do |relation, outer_index| - ids = relation.pluck(:id) - - ids.each_with_index do |diff_id, inner_index| - # This will give some space between batches of workers. - interval = DELAY_INTERVAL * outer_index + inner_index.minutes - - # A single `merge_request_diff` can be associated with way too many - # `merge_request_diff_files`. It's better to avoid batching these and - # schedule one at a time. - # - # Considering roughly 6M jobs, this should take ~30 days to process all - # of them. - # - BackgroundMigrationWorker.perform_in(interval, MIGRATION, [diff_id]) - end - end - - # We remove temporary index, because it is not required during standard - # operations and runtime. - # - remove_concurrent_index_by_name(:merge_request_diffs, TMP_INDEX) - end - - def down - if index_exists_by_name?(:merge_request_diffs, TMP_INDEX) - remove_concurrent_index_by_name(:merge_request_diffs, TMP_INDEX) - end - end -end diff --git a/db/post_migrate/20180629191052_add_partial_index_to_projects_for_last_repository_check_at.rb b/db/post_migrate/20180629191052_add_partial_index_to_projects_for_last_repository_check_at.rb new file mode 100644 index 00000000000..a701d3678db --- /dev/null +++ b/db/post_migrate/20180629191052_add_partial_index_to_projects_for_last_repository_check_at.rb @@ -0,0 +1,18 @@ +class AddPartialIndexToProjectsForLastRepositoryCheckAt < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + # Set this constant to true if this migration requires downtime. + DOWNTIME = false + + disable_ddl_transaction! + + INDEX_NAME = "index_projects_on_last_repository_check_at" + + def up + add_concurrent_index(:projects, :last_repository_check_at, where: "last_repository_check_at IS NOT NULL", name: INDEX_NAME) + end + + def down + remove_concurrent_index(:projects, :last_repository_check_at, where: "last_repository_check_at IS NOT NULL", name: INDEX_NAME) + end +end diff --git a/db/schema.rb b/db/schema.rb index 38c1710d73c..5d917abdbb5 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: 20180628124813) do +ActiveRecord::Schema.define(version: 20180629191052) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -1646,6 +1646,7 @@ ActiveRecord::Schema.define(version: 20180628124813) do add_index "projects", ["description"], name: "index_projects_on_description_trigram", using: :gin, opclasses: {"description"=>"gin_trgm_ops"} add_index "projects", ["id"], name: "index_projects_on_id_partial_for_visibility", unique: true, where: "(visibility_level = ANY (ARRAY[10, 20]))", using: :btree add_index "projects", ["last_activity_at"], name: "index_projects_on_last_activity_at", using: :btree + add_index "projects", ["last_repository_check_at"], name: "index_projects_on_last_repository_check_at", where: "(last_repository_check_at IS NOT NULL)", using: :btree add_index "projects", ["last_repository_check_failed"], name: "index_projects_on_last_repository_check_failed", using: :btree add_index "projects", ["last_repository_updated_at"], name: "index_projects_on_last_repository_updated_at", using: :btree add_index "projects", ["name"], name: "index_projects_on_name_trigram", using: :gin, opclasses: {"name"=>"gin_trgm_ops"} |