1
0
Fork 0
forked from gitea/nas

Fix single Redis connection being used across all threads (#18135)

* Fix single Redis connection being used across all Sidekiq threads

* Fix tests
This commit is contained in:
Eugen Rochko 2022-04-28 17:47:34 +02:00 committed by GitHub
parent 9bf04db23a
commit 3917353645
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
44 changed files with 243 additions and 124 deletions

View file

@ -14,6 +14,8 @@
#
class AccountConversation < ApplicationRecord
include Redisable
after_commit :push_to_streaming_api
belongs_to :account
@ -109,7 +111,7 @@ class AccountConversation < ApplicationRecord
end
def subscribed_to_timeline?
Redis.current.exists?("subscribed:#{streaming_channel}")
redis.exists?("subscribed:#{streaming_channel}")
end
def streaming_channel

View file

@ -1,6 +1,8 @@
# frozen_string_literal: true
class AccountSuggestions::GlobalSource < AccountSuggestions::Source
include Redisable
def key
:global
end
@ -28,7 +30,7 @@ class AccountSuggestions::GlobalSource < AccountSuggestions::Source
end
def account_ids_for_locale(locale)
Redis.current.zrevrange("follow_recommendations:#{locale}", 0, -1).map(&:to_i)
redis.zrevrange("follow_recommendations:#{locale}", 0, -1).map(&:to_i)
end
def to_ordered_list_key(account)

View file

@ -6,6 +6,6 @@ module Redisable
private
def redis
Redis.current
Thread.current[:redis] ||= RedisConfiguration.new.connection
end
end

View file

@ -24,6 +24,7 @@ class CustomFilter < ApplicationRecord
).freeze
include Expireable
include Redisable
belongs_to :account
@ -51,7 +52,7 @@ class CustomFilter < ApplicationRecord
def remove_cache
Rails.cache.delete("filters:#{account_id}")
Redis.current.publish("timeline:#{account_id}", Oj.dump(event: :filters_changed))
redis.publish("timeline:#{account_id}", Oj.dump(event: :filters_changed))
end
def context_must_be_valid

View file

@ -19,6 +19,7 @@ class EncryptedMessage < ApplicationRecord
self.inheritance_column = nil
include Paginable
include Redisable
scope :up_to, ->(id) { where(arel_table[:id].lteq(id)) }
@ -38,7 +39,7 @@ class EncryptedMessage < ApplicationRecord
end
def subscribed_to_timeline?
Redis.current.exists?("subscribed:#{streaming_channel}")
redis.exists?("subscribed:#{streaming_channel}")
end
def streaming_channel

View file

@ -1,6 +1,8 @@
# frozen_string_literal: true
class FollowRecommendationFilter
include Redisable
KEYS = %i(
language
status
@ -17,7 +19,7 @@ class FollowRecommendationFilter
if params['status'] == 'suppressed'
Account.joins(:follow_recommendation_suppression).order(FollowRecommendationSuppression.arel_table[:id].desc).to_a
else
account_ids = Redis.current.zrevrange("follow_recommendations:#{@language}", 0, -1).map(&:to_i)
account_ids = redis.zrevrange("follow_recommendations:#{@language}", 0, -1).map(&:to_i)
accounts = Account.where(id: account_ids).index_by(&:id)
account_ids.map { |id| accounts[id] }.compact

View file

@ -52,6 +52,7 @@ class User < ApplicationRecord
include Settings::Extend
include UserRoles
include Redisable
# The home and list feeds will be stored in Redis for this amount
# of time, and status fan-out to followers will include only people
@ -456,7 +457,7 @@ class User < ApplicationRecord
end
def regenerate_feed!
RegenerationWorker.perform_async(account_id) if Redis.current.set("account:#{account_id}:regeneration", true, nx: true, ex: 1.day.seconds)
RegenerationWorker.perform_async(account_id) if redis.set("account:#{account_id}:regeneration", true, nx: true, ex: 1.day.seconds)
end
def needs_feed_update?