Get rid of tracked field
It makes a debugging slightly easier, but is not necessary, and is a waste of resources.
This commit is contained in:
parent
a9155a94fe
commit
67b58ffdc3
3 changed files with 7 additions and 29 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue