diff options
author | Stan Hu <stanhu@gmail.com> | 2019-04-06 03:23:05 +0000 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2019-04-06 03:23:05 +0000 |
commit | 7a7c131f7bb69e398a6e2079c11c55bddd8e2bc8 (patch) | |
tree | 034e53b3f1f420aa9b7ac777b1eb458c3d4054c7 /lib | |
parent | 3198867fe3d6257aff61d6a4c0e3768f35bcc6b5 (diff) | |
parent | a8a4518099cceec5826bb9ea5d9e3198c5a10698 (diff) | |
download | gitlab-ce-7a7c131f7bb69e398a6e2079c11c55bddd8e2bc8.tar.gz |
Merge branch '58612-clean-up-notes-data' into 'master'
Clean up `noteable_id` for notes on commits
Closes #58612
See merge request gitlab-org/gitlab-ce!26104
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/database/migration_helpers.rb | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/lib/gitlab/database/migration_helpers.rb b/lib/gitlab/database/migration_helpers.rb index 3abd0600e9d..7f5eb1188fc 100644 --- a/lib/gitlab/database/migration_helpers.rb +++ b/lib/gitlab/database/migration_helpers.rb @@ -282,6 +282,7 @@ module Gitlab # Updates the value of a column in batches. # # This method updates the table in batches of 5% of the total row count. + # A `batch_size` option can also be passed to set this to a fixed number. # This method will continue updating rows until no rows remain. # # When given a block this method will yield two values to the block: @@ -320,7 +321,7 @@ module Gitlab # make things _more_ complex). # # rubocop: disable Metrics/AbcSize - def update_column_in_batches(table, column, value) + def update_column_in_batches(table, column, value, batch_size: nil) if transaction_open? raise 'update_column_in_batches can not be run inside a transaction, ' \ 'you can disable transactions by calling disable_ddl_transaction! ' \ @@ -336,14 +337,16 @@ module Gitlab return if total == 0 - # Update in batches of 5% until we run out of any rows to update. - batch_size = ((total / 100.0) * 5.0).ceil - max_size = 1000 + if batch_size.nil? + # Update in batches of 5% until we run out of any rows to update. + batch_size = ((total / 100.0) * 5.0).ceil + max_size = 1000 - # The upper limit is 1000 to ensure we don't lock too many rows. For - # example, for "merge_requests" even 1% of the table is around 35 000 - # rows for GitLab.com. - batch_size = max_size if batch_size > max_size + # The upper limit is 1000 to ensure we don't lock too many rows. For + # example, for "merge_requests" even 1% of the table is around 35 000 + # rows for GitLab.com. + batch_size = max_size if batch_size > max_size + end start_arel = table.project(table[:id]).order(table[:id].asc).take(1) start_arel = yield table, start_arel if block_given? |