Use timeline subscribed? checks

pull/32721/head
Matt Jankowski 2024-10-31 10:26:45 -04:00
parent 048609cf0e
commit 40a753c9d6
9 changed files with 11 additions and 11 deletions

View File

@ -355,7 +355,7 @@ class FeedManager
# @param [String] timeline_key # @param [String] timeline_key
# @return [Boolean] # @return [Boolean]
def push_update_required?(timeline_key) def push_update_required?(timeline_key)
redis.exists?("subscribed:#{timeline_key}") Timeline.subscribed?(timeline_key)
end end
# Check if the account is blocking or muting any of the given accounts # Check if the account is blocking or muting any of the given accounts

View File

@ -123,7 +123,7 @@ class AccountConversation < ApplicationRecord
end end
def subscribed_to_timeline? def subscribed_to_timeline?
redis.exists?("subscribed:#{streaming_channel}") Timeline.subscribed?(streaming_channel)
end end
def streaming_channel def streaming_channel

View File

@ -173,6 +173,6 @@ class FanOutOnWriteService < BaseService
end end
def subscribed_to_streaming_api?(account_id) def subscribed_to_streaming_api?(account_id)
redis.exists?("subscribed:timeline:#{account_id}") || redis.exists?("subscribed:timeline:#{account_id}:notifications") Timeline.subscribed?("timeline:#{account_id}") || Timeline.subscribed?("timeline:#{account_id}:notifications")
end end
end end

View File

@ -260,7 +260,7 @@ class NotifyService < BaseService
end end
def subscribed_to_streaming_api? def subscribed_to_streaming_api?
redis.exists?("subscribed:timeline:#{@recipient.id}") || redis.exists?("subscribed:timeline:#{@recipient.id}:notifications") Timeline.subscribed?("timeline:#{@recipient.id}") || Timeline.subscribed?("timeline:#{@recipient.id}:notifications")
end end
def push_to_conversation! def push_to_conversation!

View File

@ -14,7 +14,7 @@ class PublishAnnouncementReactionWorker
payload = Oj.dump(event: :'announcement.reaction', payload: payload) payload = Oj.dump(event: :'announcement.reaction', payload: payload)
FeedManager.instance.with_active_accounts do |account| FeedManager.instance.with_active_accounts do |account|
redis.publish("timeline:#{account.id}", payload) if redis.exists?("subscribed:timeline:#{account.id}") redis.publish("timeline:#{account.id}", payload) if Timeline.subscribed?("timeline:#{account.id}")
end end
rescue ActiveRecord::RecordNotFound rescue ActiveRecord::RecordNotFound
true true

View File

@ -15,7 +15,7 @@ class PublishScheduledAnnouncementWorker
payload = Oj.dump(event: :announcement, payload: payload) payload = Oj.dump(event: :announcement, payload: payload)
FeedManager.instance.with_active_accounts do |account| FeedManager.instance.with_active_accounts do |account|
redis.publish("timeline:#{account.id}", payload) if redis.exists?("subscribed:timeline:#{account.id}") redis.publish("timeline:#{account.id}", payload) if Timeline.subscribed?("timeline:#{account.id}")
end end
end end

View File

@ -58,6 +58,6 @@ class UnfilterNotificationsWorker
end end
def subscribed_to_streaming_api? def subscribed_to_streaming_api?
redis.exists?("subscribed:timeline:#{@recipient.id}") || redis.exists?("subscribed:timeline:#{@recipient.id}:notifications") Timeline.subscribed?("timeline:#{@recipient.id}") || Timeline.subscribed?("timeline:#{@recipient.id}:notifications")
end end
end end

View File

@ -8,7 +8,7 @@ class UnpublishAnnouncementWorker
payload = Oj.dump(event: :'announcement.delete', payload: announcement_id.to_s) payload = Oj.dump(event: :'announcement.delete', payload: announcement_id.to_s)
FeedManager.instance.with_active_accounts do |account| FeedManager.instance.with_active_accounts do |account|
redis.publish("timeline:#{account.id}", payload) if redis.exists?("subscribed:timeline:#{account.id}") redis.publish("timeline:#{account.id}", payload) if Timeline.subscribed?("timeline:#{account.id}")
end end
end end
end end

View File

@ -14,14 +14,14 @@ RSpec.describe UnfilterNotificationsWorker do
follow_request = sender.request_follow!(recipient) follow_request = sender.request_follow!(recipient)
Fabricate(:notification, filtered: true, from_account: sender, account: recipient, type: :follow_request, activity: follow_request) Fabricate(:notification, filtered: true, from_account: sender, account: recipient, type: :follow_request, activity: follow_request)
allow(redis).to receive(:publish) allow(redis).to receive(:publish)
allow(redis).to receive(:exists?).and_return(false) allow(Timeline).to receive(:subscribed?).and_return(false)
end end
shared_examples 'shared behavior' do shared_examples 'shared behavior' do
context 'when this is the last pending merge job and the user is subscribed to streaming' do context 'when this is the last pending merge job and the user is subscribed to streaming' do
before do before do
redis.set("notification_unfilter_jobs:#{recipient.id}", 1) redis.set("notification_unfilter_jobs:#{recipient.id}", 1)
allow(redis).to receive(:exists?).with("subscribed:timeline:#{recipient.id}").and_return(true) allow(Timeline).to receive(:subscribed?).with("timeline:#{recipient.id}").and_return(true)
end end
it 'unfilters notifications, adds private messages to conversations, and pushes to redis' do it 'unfilters notifications, adds private messages to conversations, and pushes to redis' do
@ -37,7 +37,7 @@ RSpec.describe UnfilterNotificationsWorker do
context 'when this is not last pending merge job and the user is subscribed to streaming' do context 'when this is not last pending merge job and the user is subscribed to streaming' do
before do before do
redis.set("notification_unfilter_jobs:#{recipient.id}", 2) redis.set("notification_unfilter_jobs:#{recipient.id}", 2)
allow(redis).to receive(:exists?).with("subscribed:timeline:#{recipient.id}").and_return(true) allow(Timeline).to receive(:subscribed?).with("timeline:#{recipient.id}").and_return(true)
end end
it 'unfilters notifications, adds private messages to conversations, and does not push to redis' do it 'unfilters notifications, adds private messages to conversations, and does not push to redis' do