diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2019-01-29 16:50:18 +0000 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2019-01-29 16:50:18 +0000 |
commit | 2d24dca485f57f3f7ecf0da0cbf07a566d90a98c (patch) | |
tree | 9b9e0ca4fd28ef590e882560144c8a68281b5952 /app | |
parent | 3a9c9e61c9dff92e76a7fef68c8b4e6a974f3ee6 (diff) | |
parent | f82eea8628770ce8451bdaf4819cd3879c163853 (diff) | |
download | gitlab-ce-2d24dca485f57f3f7ecf0da0cbf07a566d90a98c.tar.gz |
Merge branch 'ab-54270-github-iid' into 'master'
Reduce amount of locks needed for GitHub importer
Closes #54270 and #51817
See merge request gitlab-org/gitlab-ce!24102
Diffstat (limited to 'app')
-rw-r--r-- | app/models/internal_id.rb | 17 | ||||
-rw-r--r-- | app/models/project.rb | 7 |
2 files changed, 21 insertions, 3 deletions
diff --git a/app/models/internal_id.rb b/app/models/internal_id.rb index e7168d49db9..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 @@ -111,7 +122,7 @@ class InternalId < ActiveRecord::Base # Generates next internal id and returns it def generate - InternalId.transaction do + subject.transaction do # Create a record in internal_ids if one does not yet exist # and increment its last value # @@ -125,7 +136,7 @@ class InternalId < ActiveRecord::Base # # Note this will acquire a ROW SHARE lock on the InternalId record def track_greatest(new_value) - InternalId.transaction do + subject.transaction do (lookup || create_record).track_greatest_and_save!(new_value) end end @@ -148,7 +159,7 @@ class InternalId < ActiveRecord::Base # violation. We can safely roll-back the nested transaction and perform # a lookup instead to retrieve the record. def create_record - InternalId.transaction(requires_new: true) do + subject.transaction(requires_new: true) do InternalId.create!( **scope, usage: usage_value, diff --git a/app/models/project.rb b/app/models/project.rb index b509120ff83..da77479fe1f 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 |