diff options
3 files changed, 7 insertions, 29 deletions
diff --git a/lib/gitlab/background_migration/populate_untracked_uploads.rb b/lib/gitlab/background_migration/populate_untracked_uploads.rb index b8872477e63..03e7b7b71cb 100644 --- a/lib/gitlab/background_migration/populate_untracked_uploads.rb +++ b/lib/gitlab/background_migration/populate_untracked_uploads.rb @@ -50,14 +50,10 @@ module Gitlab } ].freeze - scope :untracked, -> { where(tracked: false) } - def ensure_tracked! - return if persisted? && tracked? - add_to_uploads unless in_uploads? - mark_as_tracked + delete end def in_uploads? @@ -79,10 +75,6 @@ module Gitlab ) end - def mark_as_tracked - update!(tracked: true) - end - def upload_path # UntrackedFile#path is absolute, but Upload#path depends on uploader if uploader == 'FileUploader' @@ -197,7 +189,7 @@ module Gitlab def perform(start_id, end_id) return unless migrate? - files = UntrackedFile.untracked.where(id: start_id..end_id) + files = UntrackedFile.where(id: start_id..end_id) files.each do |untracked_file| begin untracked_file.ensure_tracked! @@ -220,7 +212,7 @@ module Gitlab end def drop_temp_table_if_finished - UntrackedFile.connection.drop_table(:untracked_files_for_uploads) if UntrackedFile.untracked.empty? + UntrackedFile.connection.drop_table(:untracked_files_for_uploads) if UntrackedFile.all.empty? end end end diff --git a/lib/gitlab/background_migration/prepare_untracked_uploads.rb b/lib/gitlab/background_migration/prepare_untracked_uploads.rb index 8333a6218de..c076c13815d 100644 --- a/lib/gitlab/background_migration/prepare_untracked_uploads.rb +++ b/lib/gitlab/background_migration/prepare_untracked_uploads.rb @@ -42,10 +42,8 @@ module Gitlab unless UntrackedFile.connection.table_exists?(:untracked_files_for_uploads) UntrackedFile.connection.create_table :untracked_files_for_uploads do |t| t.string :path, limit: 600, null: false - t.boolean :tracked, default: false, null: false t.timestamps_with_timezone null: false t.index :path, unique: true - t.index :tracked end end end diff --git a/spec/lib/gitlab/background_migration/populate_untracked_uploads_spec.rb b/spec/lib/gitlab/background_migration/populate_untracked_uploads_spec.rb index 317890bd854..04719d50f5c 100644 --- a/spec/lib/gitlab/background_migration/populate_untracked_uploads_spec.rb +++ b/spec/lib/gitlab/background_migration/populate_untracked_uploads_spec.rb @@ -54,12 +54,12 @@ describe Gitlab::BackgroundMigration::PopulateUntrackedUploads, :migration, :sid expect(appearance.uploads.count).to eq(2) end - it 'sets all added or confirmed tracked files to tracked' do + it 'deletes rows after processing them' do expect(subject).to receive(:drop_temp_table_if_finished) # Don't drop the table so we can look at it expect do subject.perform(1, 1000) - end.to change { untracked_files_for_uploads.where(tracked: true).count }.from(0).to(8) + end.to change { untracked_files_for_uploads.count }.from(8).to(0) end it 'does not create duplicate uploads of already tracked files' do @@ -85,7 +85,7 @@ describe Gitlab::BackgroundMigration::PopulateUntrackedUploads, :migration, :sid expect(project2.uploads.count).to eq(0) # Only 4 have been either confirmed or added to uploads - expect(untracked_files_for_uploads.where(tracked: true).count).to eq(4) + expect(untracked_files_for_uploads.count).to eq(4) end it 'uses the start and end batch ids [only 2nd half]' do @@ -103,7 +103,7 @@ describe Gitlab::BackgroundMigration::PopulateUntrackedUploads, :migration, :sid expect(project2.uploads.count).to eq(2) # Only 4 have been either confirmed or added to uploads - expect(untracked_files_for_uploads.where(tracked: true).count).to eq(4) + expect(untracked_files_for_uploads.count).to eq(4) end it 'does not drop the temporary tracking table after processing the batch, if there are still untracked rows' do @@ -254,18 +254,6 @@ describe Gitlab::BackgroundMigration::PopulateUntrackedUploads::UntrackedFile do end end - describe '#mark_as_tracked' do - it 'saves the record with tracked set to true' do - untracked_file = create_untracked_file("/-/system/appearance/logo/1/some_logo.jpg") - - expect do - untracked_file.mark_as_tracked - end.to change { untracked_file.tracked }.from(false).to(true) - - expect(untracked_file.persisted?).to be_truthy - end - end - describe '#upload_path' do def assert_upload_path(file_path, expected_upload_path) untracked_file = create_untracked_file(file_path) |