summaryrefslogtreecommitdiff
path: root/lib/gitlab/background_migration
diff options
context:
space:
mode:
authorMichael Kozono <mkozono@gmail.com>2017-11-08 12:31:51 -0800
committerMichael Kozono <mkozono@gmail.com>2017-12-01 15:26:41 -0800
commit41412fec5b9aea8a6104320c5b554ffdabe52506 (patch)
treedf8ee71223795e2ebfe92f8a6617a6d58afe1cd4 /lib/gitlab/background_migration
parent36611773e920ebaa1c1c8d603107f47200fb8e00 (diff)
downloadgitlab-ce-41412fec5b9aea8a6104320c5b554ffdabe52506.tar.gz
Avoid instantiating an AR object and ignore dupes
Diffstat (limited to 'lib/gitlab/background_migration')
-rw-r--r--lib/gitlab/background_migration/prepare_unhashed_uploads.rb16
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/gitlab/background_migration/prepare_unhashed_uploads.rb b/lib/gitlab/background_migration/prepare_unhashed_uploads.rb
index 7c426022304..982c0ff5320 100644
--- a/lib/gitlab/background_migration/prepare_unhashed_uploads.rb
+++ b/lib/gitlab/background_migration/prepare_unhashed_uploads.rb
@@ -75,10 +75,24 @@ module Gitlab
def insert_file_paths(file_paths)
file_paths.each do |file_path|
- UnhashedUploadFile.create!(path: file_path)
+ insert_file_path(file_path)
end
end
+ def insert_file_path(file_path)
+ table_columns_and_values = 'unhashed_upload_files (path, created_at, updated_at) VALUES (?, ?, ?)'
+
+ sql = if Gitlab::Database.postgresql?
+ "INSERT INTO #{table_columns_and_values} ON CONFLICT DO NOTHING;"
+ else
+ "INSERT IGNORE INTO #{table_columns_and_values};"
+ end
+
+ timestamp = Time.now.utc.iso8601
+ sql = ActiveRecord::Base.send(:sanitize_sql_array, [sql, file_path, timestamp, timestamp])
+ ActiveRecord::Base.connection.execute(sql)
+ end
+
def schedule_populate_untracked_uploads_jobs
bulk_queue_background_migration_jobs_by_range(UnhashedUploadFile, FOLLOW_UP_MIGRATION)
end