about summary refs log tree commit diff
path: root/app/workers/scheduler
diff options
context:
space:
mode:
authorFire Demon <firedemon@creature.cafe>2020-07-21 20:58:34 -0500
committerFire Demon <firedemon@creature.cafe>2020-08-30 05:44:01 -0500
commit43fa66fe39e03c8af4b77b4c01798bf8ca0dd4aa (patch)
tree6ce3e03560825e03c1000f07ef60665be60206eb /app/workers/scheduler
parent43b25edb4f8be2314eb0d8f22d52dded24c04d0a (diff)
[Database] Add task to prune empty and orphaned items
Diffstat (limited to 'app/workers/scheduler')
-rw-r--r--app/workers/scheduler/database_cleanup_scheduler.rb15
1 files changed, 15 insertions, 0 deletions
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