mirror of
https://github.com/glitch-soc/mastodon.git
synced 2025-12-13 15:58:50 +00:00
Add age/expiry duration constants to BulkImport class (#32839)
This commit is contained in:
@@ -9,10 +9,16 @@ class Vacuum::ImportsVacuum
|
||||
private
|
||||
|
||||
def clean_unconfirmed_imports!
|
||||
BulkImport.state_unconfirmed.where(created_at: ..10.minutes.ago).in_batches.delete_all
|
||||
BulkImport
|
||||
.confirmation_missed
|
||||
.in_batches
|
||||
.delete_all
|
||||
end
|
||||
|
||||
def clean_old_imports!
|
||||
BulkImport.where(created_at: ..1.week.ago).in_batches.delete_all
|
||||
BulkImport
|
||||
.archival_completed
|
||||
.in_batches
|
||||
.delete_all
|
||||
end
|
||||
end
|
||||
|
||||
@@ -21,6 +21,9 @@
|
||||
class BulkImport < ApplicationRecord
|
||||
self.inheritance_column = false
|
||||
|
||||
ARCHIVE_PERIOD = 1.week
|
||||
CONFIRM_PERIOD = 10.minutes
|
||||
|
||||
belongs_to :account
|
||||
has_many :rows, class_name: 'BulkImportRow', inverse_of: :bulk_import, dependent: :delete_all
|
||||
|
||||
@@ -42,6 +45,9 @@ class BulkImport < ApplicationRecord
|
||||
|
||||
validates :type, presence: true
|
||||
|
||||
scope :archival_completed, -> { where(created_at: ..ARCHIVE_PERIOD.ago) }
|
||||
scope :confirmation_missed, -> { state_unconfirmed.where(created_at: ..CONFIRM_PERIOD.ago) }
|
||||
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user