From 43fa66fe39e03c8af4b77b4c01798bf8ca0dd4aa Mon Sep 17 00:00:00 2001 From: Fire Demon Date: Tue, 21 Jul 2020 20:58:34 -0500 Subject: [Database] Add task to prune empty and orphaned items --- app/workers/scheduler/database_cleanup_scheduler.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 app/workers/scheduler/database_cleanup_scheduler.rb (limited to 'app/workers') diff --git a/app/workers/scheduler/database_cleanup_scheduler.rb b/app/workers/scheduler/database_cleanup_scheduler.rb new file mode 100644 index 000000000..8910d6831 --- /dev/null +++ b/app/workers/scheduler/database_cleanup_scheduler.rb @@ -0,0 +1,15 @@ +# 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 + AccountConversation.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(:statuses).where(statuses: { id: nil }).destroy_all + Setting.rewhere(thing_type: 'User').where.not(thing_id: User.select(:id)).destroy_all + end +end -- cgit