about summary refs log tree commit diff
path: root/app/lib
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2022-11-28 11:33:34 +0100
committerClaire <claire.github-309c@sitedethib.com>2022-11-28 11:33:34 +0100
commita2e7997592dd86baa7595c41eed274be4c200d07 (patch)
treeb4c21af8bdf541d8156beb29e9f53766bd1fbadd /app/lib
parent6517b7b9f02f8590a8f9c5aa04e3ef9efeb4e757 (diff)
parentcec1e902e006730f68bde0a4334e5b819a12a475 (diff)
Merge branch 'main' into glitch-soc/merge-upstream
Conflicts:
- `README.md`:
  Our README is completely different.
  Discarded upstream changes.
Diffstat (limited to 'app/lib')
-rw-r--r--app/lib/vacuum/statuses_vacuum.rb43
1 files changed, 18 insertions, 25 deletions
diff --git a/app/lib/vacuum/statuses_vacuum.rb b/app/lib/vacuum/statuses_vacuum.rb
index 41d6ba270..d1c4e7197 100644
--- a/app/lib/vacuum/statuses_vacuum.rb
+++ b/app/lib/vacuum/statuses_vacuum.rb
@@ -8,47 +8,40 @@ class Vacuum::StatusesVacuum
   end
 
   def perform
-    vacuum_statuses! if retention_period?
+    vacuum_statuses! if @retention_period.present?
   end
 
   private
 
   def vacuum_statuses!
-    statuses_scope.find_in_batches do |statuses|
+    statuses_scope.in_batches do |statuses|
       # Side-effects not covered by foreign keys, such
       # as the search index, must be handled first.
-
-      remove_from_account_conversations(statuses)
-      remove_from_search_index(statuses)
-
-      # Foreign keys take care of most associated records
-      # for us. Media attachments will be orphaned.
-
-      Status.where(id: statuses.map(&:id)).delete_all
+      statuses.direct_visibility
+              .includes(mentions: :account)
+              .find_each do |status|
+        # TODO: replace temporary solution - call of private model method
+        status.send(:unlink_from_conversations)
+      end
+      remove_from_search_index(statuses.ids) if Chewy.enabled?
+
+      # Foreign keys take care of most associated records for us.
+      # Media attachments will be orphaned.
+      statuses.delete_all
     end
   end
 
   def statuses_scope
-    Status.unscoped.kept.where(account: Account.remote).where(Status.arel_table[:id].lt(retention_period_as_id)).select(:id, :visibility)
+    Status.unscoped.kept
+          .joins(:account).merge(Account.remote)
+          .where('statuses.id < ?', retention_period_as_id)
   end
 
   def retention_period_as_id
     Mastodon::Snowflake.id_at(@retention_period.ago, with_random: false)
   end
 
-  def analyze_statuses!
-    ActiveRecord::Base.connection.execute('ANALYZE statuses')
-  end
-
-  def remove_from_account_conversations(statuses)
-    Status.where(id: statuses.select(&:direct_visibility?).map(&:id)).includes(:account, mentions: :account).each(&:unlink_from_conversations)
-  end
-
-  def remove_from_search_index(statuses)
-    with_redis { |redis| redis.sadd('chewy:queue:StatusesIndex', statuses.map(&:id)) } if Chewy.enabled?
-  end
-
-  def retention_period?
-    @retention_period.present?
+  def remove_from_search_index(status_ids)
+    with_redis { |redis| redis.sadd('chewy:queue:StatusesIndex', status_ids) }
   end
 end