Skip to content

Commit

Permalink
Fix vacuum scheduler missing lock, locks never expiring (mastodon#19458)
Browse files Browse the repository at this point in the history
Remove vacuuming of orphaned preview cards
  • Loading branch information
Gargron authored and kadoshita committed Nov 19, 2022
1 parent e55d581 commit 5c94bf2
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 15 deletions.
2 changes: 1 addition & 1 deletion app/lib/vacuum/media_attachments_vacuum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ def initialize(retention_period)
end

def perform
vacuum_cached_files! if retention_period?
vacuum_orphaned_records!
vacuum_cached_files! if retention_period?
end

private
Expand Down
9 changes: 0 additions & 9 deletions app/lib/vacuum/preview_cards_vacuum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ def initialize(retention_period)

def perform
vacuum_cached_images! if retention_period?
vacuum_orphaned_records!
end

private
Expand All @@ -21,18 +20,10 @@ def vacuum_cached_images!
end
end

def vacuum_orphaned_records!
orphaned_preview_cards.in_batches.destroy_all
end

def preview_cards_past_retention_period
PreviewCard.cached.where(PreviewCard.arel_table[:updated_at].lt(@retention_period.ago))
end

def orphaned_preview_cards
PreviewCard.where('NOT EXISTS (SELECT 1 FROM preview_cards_statuses WHERE preview_cards_statuses.preview_card_id = preview_cards.id)').where(PreviewCard.arel_table[:created_at].lt(TTL.ago))
end

def retention_period?
@retention_period.present?
end
Expand Down
2 changes: 1 addition & 1 deletion app/workers/scheduler/vacuum_scheduler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class Scheduler::VacuumScheduler
include Sidekiq::Worker

sidekiq_options retry: 0
sidekiq_options retry: 0, lock: :until_executed

def perform
vacuum_operations.each do |operation|
Expand Down
1 change: 1 addition & 0 deletions config/initializers/sidekiq.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@
config.reaper_count = 1000
config.reaper_interval = 600
config.reaper_timeout = 150
config.lock_ttl = 50.days.to_i
end
4 changes: 0 additions & 4 deletions spec/lib/vacuum/preview_cards_vacuum_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,5 @@
it 'does not delete attached preview cards' do
expect(new_preview_card.reload).to be_persisted
end

it 'deletes preview cards not attached to any status' do
expect { orphaned_preview_card.reload }.to raise_error ActiveRecord::RecordNotFound
end
end
end

0 comments on commit 5c94bf2

Please sign in to comment.