mirror of
https://github.com/mastodon/mastodon.git
synced 2025-09-05 17:31:12 +00:00
Merge 0af0014ef9
into 14cb5ff881
This commit is contained in:
commit
f0fe2e2b35
|
@ -48,6 +48,14 @@ class BulkImport < ApplicationRecord
|
|||
scope :archival_completed, -> { where(created_at: ..ARCHIVE_PERIOD.ago) }
|
||||
scope :confirmation_missed, -> { state_unconfirmed.where(created_at: ..CONFIRM_PERIOD.ago) }
|
||||
|
||||
def failure_count
|
||||
processed_items - imported_items
|
||||
end
|
||||
|
||||
def processing_complete?
|
||||
processed_items == total_items
|
||||
end
|
||||
|
||||
def self.progress!(bulk_import_id, imported: false)
|
||||
# Use `increment_counter` so that the incrementation is done atomically in the database
|
||||
BulkImport.increment_counter(:processed_items, bulk_import_id)
|
||||
|
@ -55,6 +63,6 @@ class BulkImport < ApplicationRecord
|
|||
|
||||
# Since the incrementation has been done atomically, concurrent access to `bulk_import` is now bening
|
||||
bulk_import = BulkImport.find(bulk_import_id)
|
||||
bulk_import.update!(state: :finished, finished_at: Time.now.utc) if bulk_import.processed_items == bulk_import.total_items
|
||||
bulk_import.update!(state: :finished, finished_at: Time.now.utc) if bulk_import.processing_complete?
|
||||
end
|
||||
end
|
||||
|
|
|
@ -20,7 +20,7 @@ class BulkImportService < BaseService
|
|||
import_lists!
|
||||
end
|
||||
|
||||
@import.update!(state: :finished, finished_at: Time.now.utc) if @import.processed_items == @import.total_items
|
||||
@import.update!(state: :finished, finished_at: Time.now.utc) if @import.processing_complete?
|
||||
rescue
|
||||
@import.update!(state: :finished, finished_at: Time.now.utc)
|
||||
|
||||
|
|
|
@ -60,9 +60,6 @@
|
|||
= l(import.created_at)
|
||||
|
||||
%td
|
||||
- num_failed = import.processed_items - import.imported_items
|
||||
- if num_failed.positive?
|
||||
- if import.state_finished?
|
||||
= link_to num_failed, failures_settings_import_path(import, format: 'csv')
|
||||
- else
|
||||
= num_failed
|
||||
- if import.failure_count.positive?
|
||||
= link_to_if import.state_finished?, import.failure_count, failures_settings_import_path(import, format: :csv) do
|
||||
= import.failure_count
|
||||
|
|
|
@ -39,4 +39,28 @@ RSpec.describe BulkImport do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#failure_count' do
|
||||
subject { described_class.new(processed_items: 100, imported_items: 90).failure_count }
|
||||
|
||||
it { is_expected.to eq(10) }
|
||||
end
|
||||
|
||||
describe '#processing_complete?' do
|
||||
subject { Fabricate.build :bulk_import, processed_items:, total_items: }
|
||||
|
||||
context 'when processed and total are the same' do
|
||||
let(:processed_items) { 100 }
|
||||
let(:total_items) { 100 }
|
||||
|
||||
it { is_expected.to be_processing_complete }
|
||||
end
|
||||
|
||||
context 'when processed and total are not the same' do
|
||||
let(:processed_items) { 100 }
|
||||
let(:total_items) { 200 }
|
||||
|
||||
it { is_expected.to_not be_processing_complete }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user