about summary refs log tree commit diff
path: root/app/workers
diff options
context:
space:
mode:
authorbeatrix <beatrix.bitrot@gmail.com>2017-10-18 17:57:42 -0400
committerGitHub <noreply@github.com>2017-10-18 17:57:42 -0400
commitc75665127878f41af2547b12b8723963c04d305b (patch)
treed8275432c259d0fcd1385c163d7f2472b4a8684c /app/workers
parent4421f6598f5883908fb25743977306f19a0b0f0f (diff)
parenteb907a5babed83a73788b16772fb2cba6db8c2b4 (diff)
Merge pull request #188 from glitch-soc/merge-upstream-2-0-0
Merge with upstream v2.0.0
Diffstat (limited to 'app/workers')
-rw-r--r--app/workers/scheduler/feed_cleanup_scheduler.rb28
1 files changed, 23 insertions, 5 deletions
diff --git a/app/workers/scheduler/feed_cleanup_scheduler.rb b/app/workers/scheduler/feed_cleanup_scheduler.rb
index 222f5ed84..cfa2d31a4 100644
--- a/app/workers/scheduler/feed_cleanup_scheduler.rb
+++ b/app/workers/scheduler/feed_cleanup_scheduler.rb
@@ -5,18 +5,36 @@ class Scheduler::FeedCleanupScheduler
   include Sidekiq::Worker
 
   def perform
+    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')
+        # 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)
+        redis.del(reblog_key)
+      end
+    end
+
+    # Remove all of the reblog tracking keys we just removed the
+    # references to.
     redis.pipelined do
-      inactive_users.each do |account_id|
-        redis.del(FeedManager.instance.key(:home, account_id))
-        redis.del(FeedManager.instance.key(:home, account_id, 'reblogs'))
+      reblogged_id_sets.each do |account_id, future|
+        future.value.each do |reblogged_id|
+          reblog_set_key = feedmanager.key(:home, account_id, "reblogs:#{reblogged_id}")
+          redis.del(reblog_set_key)
+        end
       end
     end
   end
 
   private
 
-  def inactive_users
-    @inactive_users ||= User.confirmed.inactive.pluck(:account_id)
+  def inactive_user_ids
+    @inactive_user_ids ||= User.confirmed.inactive.pluck(:account_id)
   end
 
   def redis