diff options
author | Rémy Coutable <remy@rymai.me> | 2016-07-08 10:18:42 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2016-07-08 10:18:42 +0000 |
commit | 01d1be7bf1ffca28ce56dadeffcb426acfe8b0bf (patch) | |
tree | 1e84591d64898085ee6564b34f634d7d27c80a8d /db | |
parent | 2c650b6f30d2e76cf632d6ce5771859aed67ac48 (diff) | |
parent | 2c6fe72265d250e47c03f27dc274b59d3e7e93f5 (diff) | |
download | gitlab-ce-01d1be7bf1ffca28ce56dadeffcb426acfe8b0bf.tar.gz |
Merge branch 'fix/import-url-migration' into 'master'
import_url migration performance improvements
Nullifying empty import_urls upfront so the number of projects with import_url not NULL decreases to 1/5.
Also, now processing batches in blocks of 1000, with a threaded process - a bit experimental.
See merge request !5149
Diffstat (limited to 'db')
-rw-r--r-- | db/migrate/20160620110927_fix_no_validatable_import_url.rb | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/db/migrate/20160620110927_fix_no_validatable_import_url.rb b/db/migrate/20160620110927_fix_no_validatable_import_url.rb index 82a616c62d9..a3f5073d511 100644 --- a/db/migrate/20160620110927_fix_no_validatable_import_url.rb +++ b/db/migrate/20160620110927_fix_no_validatable_import_url.rb @@ -11,7 +11,7 @@ class FixNoValidatableImportUrl < ActiveRecord::Migration attr_reader :results, :query - def initialize(batch_size: 100, query:) + def initialize(batch_size: 1000, query:) @offset = 0 @batch_size = batch_size @query = query @@ -58,22 +58,38 @@ class FixNoValidatableImportUrl < ActiveRecord::Migration return end + say('Nullifying empty import URLs') + + nullify_empty_urls + say('Cleaning up invalid import URLs... This may take a few minutes if we have a large number of imported projects.') - invalid_import_url_project_ids.each { |project_id| cleanup_import_url(project_id) } + process_invalid_import_urls end - def invalid_import_url_project_ids - ids = [] + def process_invalid_import_urls batches = SqlBatches.new(query: "SELECT id, import_url FROM projects WHERE import_url IS NOT NULL") while batches.next? + project_ids = [] + batches.results.each do |result| - ids << result['id'] unless valid_url?(result['import_url']) + project_ids << result['id'] unless valid_url?(result['import_url']) end + + process_batch(project_ids) end - ids + end + + def process_batch(project_ids) + Thread.new do + begin + project_ids.each { |project_id| cleanup_import_url(project_id) } + ensure + ActiveRecord::Base.connection.close + end + end.join end def valid_url?(url) @@ -83,4 +99,8 @@ class FixNoValidatableImportUrl < ActiveRecord::Migration def cleanup_import_url(project_id) execute("UPDATE projects SET import_url = NULL WHERE id = #{project_id}") end + + def nullify_empty_urls + execute("UPDATE projects SET import_url = NULL WHERE import_url = ''") + end end |