This instance will be upgraded to Heptapod 0.31.0 (final) on 2022-05-24 at 14:00 UTC+2 (a few minutes of down time)

Commit ae61f49c authored by Michael Kozono's avatar Michael Kozono
Browse files

Get rid of tracked field

It makes a debugging slightly easier, but is not necessary, and is a waste of resources.
parent 37005d759d97
......@@ -50,14 +50,10 @@ class UntrackedFile < ActiveRecord::Base
}
].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 @@ def add_to_uploads
)
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 @@ def uploader_class
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 @@ def migrate?
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 @@ def ensure_temporary_tracking_table_exists
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 @@
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 @@
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 @@
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 @@ class Note < ActiveRecord::Base
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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment