From fede3a0b75e5db720bd4684faca5626d4ef109d2 Mon Sep 17 00:00:00 2001 From: Andreas Brandl Date: Wed, 2 Jan 2019 16:50:37 +0100 Subject: Flush InternalId records after import After the import has finished, we flush (delete) the InternalId records related to the project at hand. This means we're starting over with tracking correct internal id values, a new record will be created automatically when the next internal id is generated. The GitHub importer assigns iid values by using supplied values from GitHub. We skip tracking internal id values during the import in favor of higher concurrency. Deleting any InternalId records after the import has finished is an extra measure to guarantee consistency. Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/54270. --- app/models/internal_id.rb | 11 +++++++++++ app/models/project.rb | 7 +++++++ 2 files changed, 18 insertions(+) (limited to 'app') diff --git a/app/models/internal_id.rb b/app/models/internal_id.rb index 4eb211eff61..e75c6eb2331 100644 --- a/app/models/internal_id.rb +++ b/app/models/internal_id.rb @@ -66,6 +66,17 @@ class InternalId < ActiveRecord::Base InternalIdGenerator.new(subject, scope, usage, init).generate end + # Flushing records is generally safe in a sense that those + # records are going to be re-created when needed. + # + # A filter condition has to be provided to not accidentally flush + # records for all projects. + def flush_records!(filter) + raise ArgumentError, "filter cannot be empty" if filter.blank? + + where(filter).delete_all + end + def available? @available_flag ||= ActiveRecord::Migrator.current_version >= REQUIRED_SCHEMA_VERSION # rubocop:disable Gitlab/PredicateMemoization end diff --git a/app/models/project.rb b/app/models/project.rb index 15465d9b356..7f6da130658 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1585,6 +1585,13 @@ class Project < ActiveRecord::Base def after_import repository.after_import wiki.repository.after_import + + # The import assigns iid values on its own, e.g. by re-using GitHub ids. + # Flush existing InternalId records for this project for consistency reasons. + # Those records are going to be recreated with the next normal creation + # of a model instance (e.g. an Issue). + InternalId.flush_records!(project: self) + import_state.finish import_state.remove_jid update_project_counter_caches -- cgit v1.2.1