diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-21 09:09:01 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-21 09:09:01 +0000 |
commit | a53d2c37c4934f564caa94543dd4cf5af1703e2d (patch) | |
tree | a028dc39771a4612a9845ab700a73af2d6f3f51b /lib/gitlab/background_migration/cleanup_optimistic_locking_nulls.rb | |
parent | 18b8435318887d3fc6e9f9d305967a953cdd7d3f (diff) | |
download | gitlab-ce-a53d2c37c4934f564caa94543dd4cf5af1703e2d.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/background_migration/cleanup_optimistic_locking_nulls.rb')
-rw-r--r-- | lib/gitlab/background_migration/cleanup_optimistic_locking_nulls.rb | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/gitlab/background_migration/cleanup_optimistic_locking_nulls.rb b/lib/gitlab/background_migration/cleanup_optimistic_locking_nulls.rb new file mode 100644 index 00000000000..3aa1ebb49f9 --- /dev/null +++ b/lib/gitlab/background_migration/cleanup_optimistic_locking_nulls.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true +# rubocop:disable Style/Documentation + +module Gitlab + module BackgroundMigration + class CleanupOptimisticLockingNulls + QUERY_ITEM_SIZE = 1_000 + + # table - The name of the table the migration is performed for. + # start_id - The ID of the object to start at + # stop_id - The ID of the object to end at + def perform(start_id, stop_id, table) + model = define_model_for(table) + + # After analysis done, a batch size of 1,000 items per query was found to be + # the most optimal. Discussion in https://gitlab.com/gitlab-org/gitlab/-/merge_requests/18418#note_282285336 + (start_id..stop_id).each_slice(QUERY_ITEM_SIZE).each do |range| + model + .where(lock_version: nil) + .where(id: range) + .update_all(lock_version: 0) + end + end + + def define_model_for(table) + Class.new(ActiveRecord::Base) do + self.table_name = table + end + end + end + end +end |