]> cat aescling's git repositories - mastodon.git/commitdiff
Fix concurrent unfollowing decrementing follower count more than once (#18527)
authorEugen Rochko <eugen@zeonfederated.com>
Thu, 26 May 2022 20:14:47 +0000 (22:14 +0200)
committersingle-right-quote <11325618-aescling@users.noreply.gitlab.com>
Fri, 27 May 2022 03:55:21 +0000 (23:55 -0400)
app/services/unfollow_service.rb

index 151f3674fd63a32334b7dd1048b954f09190ec2e..d83a60e4e72a8f7d42904e7748e8755de8ac0f95 100644 (file)
@@ -2,6 +2,8 @@
 
 class UnfollowService < BaseService
   include Payloadable
+  include Redisable
+  include Lockable
 
   # Unfollow and notify the remote user
   # @param [Account] source_account Where to unfollow from
@@ -13,7 +15,9 @@ class UnfollowService < BaseService
     @target_account = target_account
     @options        = options
 
-    unfollow! || undo_follow_request!
+    with_lock("relationship:#{[source_account.id, target_account.id].sort.join(':')}") do
+      unfollow! || undo_follow_request!
+    end
   end
 
   private