]> cat aescling's git repositories - mastodon.git/commitdiff
Move merging/unmerging of timelines into background. Move blocking into
authorEugen Rochko <eugen@zeonfederated.com>
Mon, 23 Jan 2017 20:29:34 +0000 (21:29 +0100)
committerEugen Rochko <eugen@zeonfederated.com>
Mon, 23 Jan 2017 20:29:34 +0000 (21:29 +0100)
background as well since it's a computationally expensive

app/controllers/api/v1/accounts_controller.rb
app/lib/feed_manager.rb
app/services/follow_service.rb
app/services/unfollow_service.rb
app/workers/block_worker.rb [new file with mode: 0644]
app/workers/merge_worker.rb [new file with mode: 0644]
app/workers/unmerge_worker.rb [new file with mode: 0644]

index bd52dfb2c533c0f90977290f7f8dbad957bc4867..234844ed7678156c1b489fe5b1a30ab322265b01 100644 (file)
@@ -65,8 +65,13 @@ class Api::V1::AccountsController < ApiController
   end
 
   def block
-    BlockService.new.call(current_user.account, @account)
-    set_relationship
+    BlockWorker.perform_async(current_user.account_id, @account.id)
+
+    @following   = { @account.id => false }
+    @followed_by = { @account.id => false }
+    @blocking    = { @account.id => true }
+    @requested   = { @account.id => false }
+
     render action: :relationship
   end
 
index 19f9dc16f5eb8b1f5130860603319593f9fb9042..cdd26e69c62e72349ea93456a474d35c4bac6ada 100644 (file)
@@ -50,6 +50,15 @@ class FeedManager
     trim(:home, into_account.id)
   end
 
+  def unmerge_from_timeline(from_account, into_account)
+    timeline_key = key(:home, into_account.id)
+
+    from_account.statuses.select('id').find_each do |status|
+      redis.zrem(timeline_key, status.id)
+      redis.zremrangebyscore(timeline_key, status.id, status.id)
+    end
+  end
+
   def inline_render(target_account, template, object)
     rabl_scope = Class.new do
       include RoutingHelper
index 555f01b6d6606bca145b8e7fce2d647cd2322085..87c16a6219180c8c3fcbf281f6d1b8b55228e7ec 100644 (file)
@@ -38,7 +38,7 @@ class FollowService < BaseService
       NotificationWorker.perform_async(follow.stream_entry.id, target_account.id)
     end
 
-    FeedManager.instance.merge_into_timeline(target_account, source_account)
+    MergeWorker.perform_async(target_account.id, source_account.id)
     Pubsubhubbub::DistributionWorker.perform_async(follow.stream_entry.id)
 
     follow
index 7973a361116e22fbc4d1b07cf9ee350cf77e34fe..f469793c1afcc0808eefe88f9a34e6f7d61160c7 100644 (file)
@@ -7,21 +7,6 @@ class UnfollowService < BaseService
   def call(source_account, target_account)
     follow = source_account.unfollow!(target_account)
     NotificationWorker.perform_async(follow.stream_entry.id, target_account.id) unless target_account.local?
-    unmerge_from_timeline(target_account, source_account)
-  end
-
-  private
-
-  def unmerge_from_timeline(from_account, into_account)
-    timeline_key = FeedManager.instance.key(:home, into_account.id)
-
-    from_account.statuses.select('id').find_each do |status|
-      redis.zrem(timeline_key, status.id)
-      redis.zremrangebyscore(timeline_key, status.id, status.id)
-    end
-  end
-
-  def redis
-    Redis.current
+    UnmergeWorker.perform_async(target_account.id, source_account.id)
   end
 end
diff --git a/app/workers/block_worker.rb b/app/workers/block_worker.rb
new file mode 100644 (file)
index 0000000..dc00db1
--- /dev/null
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+class BlockWorker
+  include Sidekiq::Worker
+
+  def perform(account_id, target_account_id)
+    BlockService.new.call(Account.find(account_id), Account.find(target_account_id))
+  end
+end
diff --git a/app/workers/merge_worker.rb b/app/workers/merge_worker.rb
new file mode 100644 (file)
index 0000000..0f288f4
--- /dev/null
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+class MergeWorker
+  include Sidekiq::Worker
+
+  def perform(from_account_id, into_account_id)
+    FeedManager.instance.merge_into_timeline(Account.find(from_account_id), Account.find(into_account_id))
+  end
+end
diff --git a/app/workers/unmerge_worker.rb b/app/workers/unmerge_worker.rb
new file mode 100644 (file)
index 0000000..dbf7243
--- /dev/null
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+class UnmergeWorker
+  include Sidekiq::Worker
+
+  def perform(from_account_id, into_account_id)
+    FeedManager.instance.unmerge_from_timeline(Account.find(from_account_id), Account.find(into_account_id))
+  end
+end