about summary refs log tree commit diff
path: root/app/workers/scheduler
diff options
context:
space:
mode:
authorDavid Yip <yipdw@member.fsf.org>2017-12-06 15:40:59 -0600
committerDavid Yip <yipdw@member.fsf.org>2017-12-06 15:40:59 -0600
commitf1cbea77a4a52929244198dcbde26d63d837489a (patch)
tree82645dbc9eec65f870ce7a211355deb6bdc29f29 /app/workers/scheduler
parent21e28a5caa5e92165322c4127c89a6f88e68198a (diff)
parent8ca91cef45417947607079118b1af07c9774ae58 (diff)
Merge remote-tracking branch 'personal/merge/tootsuite/master' into gs-master
Diffstat (limited to 'app/workers/scheduler')
-rw-r--r--app/workers/scheduler/feed_cleanup_scheduler.rb40
1 files changed, 30 insertions, 10 deletions
diff --git a/app/workers/scheduler/feed_cleanup_scheduler.rb b/app/workers/scheduler/feed_cleanup_scheduler.rb
index cfa2d31a4..23fa7672b 100644
--- a/app/workers/scheduler/feed_cleanup_scheduler.rb
+++ b/app/workers/scheduler/feed_cleanup_scheduler.rb
@@ -5,16 +5,30 @@ class Scheduler::FeedCleanupScheduler
   include Sidekiq::Worker
 
   def perform
+    clean_home_feeds!
+    clean_list_feeds!
+  end
+
+  private
+
+  def clean_home_feeds!
+    clean_feeds!(inactive_account_ids, :home)
+  end
+
+  def clean_list_feeds!
+    clean_feeds!(inactive_list_ids, :list)
+  end
+
+  def clean_feeds!(ids, type)
     reblogged_id_sets = {}
-    feedmanager = FeedManager.instance
 
     redis.pipelined do
-      inactive_user_ids.each do |account_id|
-        redis.del(feedmanager.key(:home, account_id))
-        reblog_key = feedmanager.key(:home, account_id, 'reblogs')
+      ids.each do |feed_id|
+        redis.del(feed_manager.key(type, feed_id))
+        reblog_key = feed_manager.key(type, feed_id, 'reblogs')
         # We collect a future for this: we don't block while getting
         # it, but we can iterate over it later.
-        reblogged_id_sets[account_id] = redis.zrange(reblog_key, 0, -1)
+        reblogged_id_sets[feed_id] = redis.zrange(reblog_key, 0, -1)
         redis.del(reblog_key)
       end
     end
@@ -22,19 +36,25 @@ class Scheduler::FeedCleanupScheduler
     # Remove all of the reblog tracking keys we just removed the
     # references to.
     redis.pipelined do
-      reblogged_id_sets.each do |account_id, future|
+      reblogged_id_sets.each do |feed_id, future|
         future.value.each do |reblogged_id|
-          reblog_set_key = feedmanager.key(:home, account_id, "reblogs:#{reblogged_id}")
+          reblog_set_key = feed_manager.key(type, feed_id, "reblogs:#{reblogged_id}")
           redis.del(reblog_set_key)
         end
       end
     end
   end
 
-  private
+  def inactive_account_ids
+    @inactive_account_ids ||= User.confirmed.inactive.pluck(:account_id)
+  end
+
+  def inactive_list_ids
+    List.where(account_id: inactive_account_ids).pluck(:id)
+  end
 
-  def inactive_user_ids
-    @inactive_user_ids ||= User.confirmed.inactive.pluck(:account_id)
+  def feed_manager
+    FeedManager.instance
   end
 
   def redis