about summary refs log tree commit diff
path: root/app/workers/scheduler/database_cleanup_scheduler.rb
blob: 033556099b5e7773101cf530c1135b7d61c066b5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# frozen_string_literal: true

class Scheduler::DatabaseCleanupScheduler
  include Sidekiq::Worker

  sidekiq_options lock: :until_executed, retry: 0

  def perform
    Conversation.left_outer_joins(:statuses).where(statuses: { id: nil }).destroy_all
    Tag.left_outer_joins(:statuses).where(statuses: { id: nil }).destroy_all
    StatusStat.left_outer_joins(:status).where(statuses: { id: nil }).destroy_all
    Setting.rewhere(thing_type: 'User').where.not(thing_id: User.select(:id)).destroy_all
  end
end