about summary refs log tree commit diff
path: root/app/services
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2022-04-28 17:47:34 +0200
committerGitHub <noreply@github.com>2022-04-28 17:47:34 +0200
commit3917353645b91dae04f7d9b81162fead6f73072a (patch)
tree202cbf93dfa378c26a291900ea65ec088ee5b5cc /app/services
parent9bf04db23acf10e05ffdf7def06c246081f8f065 (diff)
Fix single Redis connection being used across all threads (#18135)
* Fix single Redis connection being used across all Sidekiq threads

* Fix tests
Diffstat (limited to 'app/services')
-rw-r--r--app/services/activitypub/process_account_service.rb3
-rw-r--r--app/services/activitypub/process_status_update_service.rb3
-rw-r--r--app/services/fan_out_on_write_service.rb14
-rw-r--r--app/services/fetch_link_card_service.rb4
-rw-r--r--app/services/precompute_feed_service.rb4
-rw-r--r--app/services/remove_status_service.rb2
-rw-r--r--app/services/resolve_account_service.rb3
-rw-r--r--app/services/vote_service.rb3
8 files changed, 23 insertions, 13 deletions
diff --git a/app/services/activitypub/process_account_service.rb b/app/services/activitypub/process_account_service.rb
index ec5140720..5649153ee 100644
--- a/app/services/activitypub/process_account_service.rb
+++ b/app/services/activitypub/process_account_service.rb
@@ -3,6 +3,7 @@
 class ActivityPub::ProcessAccountService < BaseService
   include JsonLdHelper
   include DomainControlHelper
+  include Redisable
 
   # Should be called with confirmed valid JSON
   # and WebFinger-resolved username and domain
@@ -289,7 +290,7 @@ class ActivityPub::ProcessAccountService < BaseService
   end
 
   def lock_options
-    { redis: Redis.current, key: "process_account:#{@uri}", autorelease: 15.minutes.seconds }
+    { redis: redis, key: "process_account:#{@uri}", autorelease: 15.minutes.seconds }
   end
 
   def process_tags
diff --git a/app/services/activitypub/process_status_update_service.rb b/app/services/activitypub/process_status_update_service.rb
index 3d9d9cb84..fb6e44c6d 100644
--- a/app/services/activitypub/process_status_update_service.rb
+++ b/app/services/activitypub/process_status_update_service.rb
@@ -2,6 +2,7 @@
 
 class ActivityPub::ProcessStatusUpdateService < BaseService
   include JsonLdHelper
+  include Redisable
 
   def call(status, json)
     raise ArgumentError, 'Status has unsaved changes' if status.changed?
@@ -241,7 +242,7 @@ class ActivityPub::ProcessStatusUpdateService < BaseService
   end
 
   def lock_options
-    { redis: Redis.current, key: "create:#{@uri}", autorelease: 15.minutes.seconds }
+    { redis: redis, key: "create:#{@uri}", autorelease: 15.minutes.seconds }
   end
 
   def record_previous_edit!
diff --git a/app/services/fan_out_on_write_service.rb b/app/services/fan_out_on_write_service.rb
index 76404c6b8..de5c5ebe4 100644
--- a/app/services/fan_out_on_write_service.rb
+++ b/app/services/fan_out_on_write_service.rb
@@ -1,6 +1,8 @@
 # frozen_string_literal: true
 
 class FanOutOnWriteService < BaseService
+  include Redisable
+
   # Push a status into home and mentions feeds
   # @param [Status] status
   # @param [Hash] options
@@ -99,20 +101,20 @@ class FanOutOnWriteService < BaseService
 
   def broadcast_to_hashtag_streams!
     @status.tags.pluck(:name).each do |hashtag|
-      Redis.current.publish("timeline:hashtag:#{hashtag.mb_chars.downcase}", anonymous_payload)
-      Redis.current.publish("timeline:hashtag:#{hashtag.mb_chars.downcase}:local", anonymous_payload) if @status.local?
+      redis.publish("timeline:hashtag:#{hashtag.mb_chars.downcase}", anonymous_payload)
+      redis.publish("timeline:hashtag:#{hashtag.mb_chars.downcase}:local", anonymous_payload) if @status.local?
     end
   end
 
   def broadcast_to_public_streams!
     return if @status.reply? && @status.in_reply_to_account_id != @account.id
 
-    Redis.current.publish('timeline:public', anonymous_payload)
-    Redis.current.publish(@status.local? ? 'timeline:public:local' : 'timeline:public:remote', anonymous_payload)
+    redis.publish('timeline:public', anonymous_payload)
+    redis.publish(@status.local? ? 'timeline:public:local' : 'timeline:public:remote', anonymous_payload)
 
     if @status.with_media?
-      Redis.current.publish('timeline:public:media', anonymous_payload)
-      Redis.current.publish(@status.local? ? 'timeline:public:local:media' : 'timeline:public:remote:media', anonymous_payload)
+      redis.publish('timeline:public:media', anonymous_payload)
+      redis.publish(@status.local? ? 'timeline:public:local:media' : 'timeline:public:remote:media', anonymous_payload)
     end
   end
 
diff --git a/app/services/fetch_link_card_service.rb b/app/services/fetch_link_card_service.rb
index 9c8b5ea20..868796a6b 100644
--- a/app/services/fetch_link_card_service.rb
+++ b/app/services/fetch_link_card_service.rb
@@ -1,6 +1,8 @@
 # frozen_string_literal: true
 
 class FetchLinkCardService < BaseService
+  include Redisable
+
   URL_PATTERN = %r{
     (#{Twitter::TwitterText::Regex[:valid_url_preceding_chars]})                                                                #   $1 preceding chars
     (                                                                                                                           #   $2 URL
@@ -155,6 +157,6 @@ class FetchLinkCardService < BaseService
   end
 
   def lock_options
-    { redis: Redis.current, key: "fetch:#{@original_url}", autorelease: 15.minutes.seconds }
+    { redis: redis, key: "fetch:#{@original_url}", autorelease: 15.minutes.seconds }
   end
 end
diff --git a/app/services/precompute_feed_service.rb b/app/services/precompute_feed_service.rb
index 61f573534..f813f06b2 100644
--- a/app/services/precompute_feed_service.rb
+++ b/app/services/precompute_feed_service.rb
@@ -1,9 +1,11 @@
 # frozen_string_literal: true
 
 class PrecomputeFeedService < BaseService
+  include Redisable
+
   def call(account)
     FeedManager.instance.populate_home(account)
   ensure
-    Redis.current.del("account:#{account.id}:regeneration")
+    redis.del("account:#{account.id}:regeneration")
   end
 end
diff --git a/app/services/remove_status_service.rb b/app/services/remove_status_service.rb
index 41730154d..dbd1f6430 100644
--- a/app/services/remove_status_service.rb
+++ b/app/services/remove_status_service.rb
@@ -146,6 +146,6 @@ class RemoveStatusService < BaseService
   end
 
   def lock_options
-    { redis: Redis.current, key: "distribute:#{@status.id}", autorelease: 5.minutes.seconds }
+    { redis: redis, key: "distribute:#{@status.id}", autorelease: 5.minutes.seconds }
   end
 end
diff --git a/app/services/resolve_account_service.rb b/app/services/resolve_account_service.rb
index 3a372ef2a..21332a03e 100644
--- a/app/services/resolve_account_service.rb
+++ b/app/services/resolve_account_service.rb
@@ -4,6 +4,7 @@ class ResolveAccountService < BaseService
   include JsonLdHelper
   include DomainControlHelper
   include WebfingerHelper
+  include Redisable
 
   # Find or create an account record for a remote user. When creating,
   # look up the user's webfinger and fetch ActivityPub data
@@ -147,6 +148,6 @@ class ResolveAccountService < BaseService
   end
 
   def lock_options
-    { redis: Redis.current, key: "resolve:#{@username}@#{@domain}", autorelease: 15.minutes.seconds }
+    { redis: redis, key: "resolve:#{@username}@#{@domain}", autorelease: 15.minutes.seconds }
   end
 end
diff --git a/app/services/vote_service.rb b/app/services/vote_service.rb
index 19e453332..b77812970 100644
--- a/app/services/vote_service.rb
+++ b/app/services/vote_service.rb
@@ -3,6 +3,7 @@
 class VoteService < BaseService
   include Authorization
   include Payloadable
+  include Redisable
 
   def call(account, poll, choices)
     authorize_with account, poll, :vote?
@@ -77,6 +78,6 @@ class VoteService < BaseService
   end
 
   def lock_options
-    { redis: Redis.current, key: "vote:#{@poll.id}:#{@account.id}" }
+    { redis: redis, key: "vote:#{@poll.id}:#{@account.id}" }
   end
 end