From 5b95be1c42ba69c9a3a79cfa990c80a5f2debfc6 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Wed, 5 Apr 2017 19:45:18 +0200 Subject: Replace calls to FeedManager#inline_render and #broadcast --- app/services/fan_out_on_write_service.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'app/services/fan_out_on_write_service.rb') diff --git a/app/services/fan_out_on_write_service.rb b/app/services/fan_out_on_write_service.rb index 106d257ba..c63fcc1fe 100644 --- a/app/services/fan_out_on_write_service.rb +++ b/app/services/fan_out_on_write_service.rb @@ -50,22 +50,22 @@ class FanOutOnWriteService < BaseService end def render_anonymous_payload(status) - @payload = FeedManager.instance.inline_render(nil, 'api/v1/statuses/show', status) + @payload = InlineRenderer.render(status, nil, 'api/v1/statuses/show') end def deliver_to_hashtags(status) Rails.logger.debug "Delivering status #{status.id} to hashtags" status.tags.pluck(:name).each do |hashtag| - FeedManager.instance.broadcast("hashtag:#{hashtag}", event: 'update', payload: @payload) - FeedManager.instance.broadcast("hashtag:#{hashtag}:local", event: 'update', payload: @payload) if status.account.local? + Redis.current.publish("hashtag:#{hashtag}", Oj.dump(event: :update, payload: @payload)) + Redis.current.publish("hashtag:#{hashtag}:local", Oj.dump(event: :update, payload: @payload)) if status.account.local? end end def deliver_to_public(status) Rails.logger.debug "Delivering status #{status.id} to public timeline" - FeedManager.instance.broadcast(:public, event: 'update', payload: @payload) - FeedManager.instance.broadcast('public:local', event: 'update', payload: @payload) if status.account.local? + Redis.current.publish('public', Oj.dump(event: 'update', payload: @payload)) + Redis.current.publish('public:local', Oj.dump(event: 'update', payload: @payload)) if status.account.local? end end -- cgit From dbd529109ea95df43aefa514c312d7397e7fc713 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Thu, 6 Apr 2017 02:26:59 +0200 Subject: Fix notifications delivered to wrong pubsub channel, optimized RemoveStatusService, slightly optimized FanOutOnWriteService again --- app/services/fan_out_on_write_service.rb | 9 +++++---- app/services/notify_service.rb | 2 +- app/services/remove_status_service.rb | 28 +++++++++++++++------------- 3 files changed, 21 insertions(+), 18 deletions(-) (limited to 'app/services/fan_out_on_write_service.rb') diff --git a/app/services/fan_out_on_write_service.rb b/app/services/fan_out_on_write_service.rb index c63fcc1fe..a25c20c93 100644 --- a/app/services/fan_out_on_write_service.rb +++ b/app/services/fan_out_on_write_service.rb @@ -51,21 +51,22 @@ class FanOutOnWriteService < BaseService def render_anonymous_payload(status) @payload = InlineRenderer.render(status, nil, 'api/v1/statuses/show') + @payload = Oj.dump(event: :update, payload: @payload) end def deliver_to_hashtags(status) Rails.logger.debug "Delivering status #{status.id} to hashtags" status.tags.pluck(:name).each do |hashtag| - Redis.current.publish("hashtag:#{hashtag}", Oj.dump(event: :update, payload: @payload)) - Redis.current.publish("hashtag:#{hashtag}:local", Oj.dump(event: :update, payload: @payload)) if status.account.local? + Redis.current.publish("hashtag:#{hashtag}", @payload) + Redis.current.publish("hashtag:#{hashtag}:local", @payload) if status.local? end end def deliver_to_public(status) Rails.logger.debug "Delivering status #{status.id} to public timeline" - Redis.current.publish('public', Oj.dump(event: 'update', payload: @payload)) - Redis.current.publish('public:local', Oj.dump(event: 'update', payload: @payload)) if status.account.local? + Redis.current.publish('public', @payload) + Redis.current.publish('public:local', @payload) if status.local? end end diff --git a/app/services/notify_service.rb b/app/services/notify_service.rb index 62508a049..ffeee5fcf 100644 --- a/app/services/notify_service.rb +++ b/app/services/notify_service.rb @@ -50,7 +50,7 @@ class NotifyService < BaseService def create_notification @notification.save! return unless @notification.browserable? - Redis.current.publish(@recipient.id, Oj.dump(event: :notification, payload: InlineRenderer.render(@notification, @recipient, 'api/v1/notifications/show'))) + Redis.current.publish("timeline:#{@recipient.id}", Oj.dump(event: :notification, payload: InlineRenderer.render(@notification, @recipient, 'api/v1/notifications/show'))) end def send_email diff --git a/app/services/remove_status_service.rb b/app/services/remove_status_service.rb index e19fdd030..60ce9987c 100644 --- a/app/services/remove_status_service.rb +++ b/app/services/remove_status_service.rb @@ -4,6 +4,8 @@ class RemoveStatusService < BaseService include StreamEntryRenderer def call(status) + @payload = Oj.dump(event: :delete, payload: status.id) + remove_from_self(status) if status.account.local? remove_from_followers(status) remove_from_mentioned(status) @@ -25,25 +27,23 @@ class RemoveStatusService < BaseService end def remove_from_followers(status) - status.account.followers.each do |follower| - next unless follower.local? + status.account.followers.where(domain: nil).each do |follower| unpush(:home, follower, status) end end def remove_from_mentioned(status) + return unless status.local? notified_domains = [] status.mentions.each do |mention| mentioned_account = mention.account - if mentioned_account.local? - unpush(:mentions, mentioned_account, status) - else - next if notified_domains.include?(mentioned_account.domain) - notified_domains << mentioned_account.domain - send_delete_salmon(mentioned_account, status) - end + next if mentioned_account.local? + next if notified_domains.include?(mentioned_account.domain) + + notified_domains << mentioned_account.domain + send_delete_salmon(mentioned_account, status) end end @@ -65,17 +65,19 @@ class RemoveStatusService < BaseService redis.zremrangebyscore(FeedManager.instance.key(type, receiver.id), status.id, status.id) end - Redis.current.publish(receiver.id, Oj.dump(event: :delete, payload: status.id)) + Redis.current.publish("timeline:#{receiver.id}", @payload) end def remove_from_hashtags(status) - status.tags.each do |tag| - Redis.current.publish("hashtag:#{tag.name}", Oj.dump(event: :delete, payload: status.id)) + status.tags.pluck(:name) do |hashtag| + Redis.current.publish("hashtag:#{hashtag}", @payload) + Redis.current.publish("hashtag:#{hashtag}:local", @payload) if status.local? end end def remove_from_public(status) - Redis.current.publish('public', Oj.dump(event: :delete, payload: status.id)) + Redis.current.publish('public', @payload) + Redis.current.publish('public:local', @payload) if status.local? end def redis -- cgit From 51d7caaf1994ee3cb531b64841e12d129dded298 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Thu, 6 Apr 2017 04:03:23 +0200 Subject: Fix wrong pubsub channel on public timelines --- app/services/fan_out_on_write_service.rb | 8 ++++---- app/services/remove_status_service.rb | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'app/services/fan_out_on_write_service.rb') diff --git a/app/services/fan_out_on_write_service.rb b/app/services/fan_out_on_write_service.rb index a25c20c93..19eedc0a7 100644 --- a/app/services/fan_out_on_write_service.rb +++ b/app/services/fan_out_on_write_service.rb @@ -58,15 +58,15 @@ class FanOutOnWriteService < BaseService Rails.logger.debug "Delivering status #{status.id} to hashtags" status.tags.pluck(:name).each do |hashtag| - Redis.current.publish("hashtag:#{hashtag}", @payload) - Redis.current.publish("hashtag:#{hashtag}:local", @payload) if status.local? + Redis.current.publish("timeline:hashtag:#{hashtag}", @payload) + Redis.current.publish("timeline:hashtag:#{hashtag}:local", @payload) if status.local? end end def deliver_to_public(status) Rails.logger.debug "Delivering status #{status.id} to public timeline" - Redis.current.publish('public', @payload) - Redis.current.publish('public:local', @payload) if status.local? + Redis.current.publish('timeline:public', @payload) + Redis.current.publish('timeline:public:local', @payload) if status.local? end end diff --git a/app/services/remove_status_service.rb b/app/services/remove_status_service.rb index 60ce9987c..50bb7fc97 100644 --- a/app/services/remove_status_service.rb +++ b/app/services/remove_status_service.rb @@ -70,14 +70,14 @@ class RemoveStatusService < BaseService def remove_from_hashtags(status) status.tags.pluck(:name) do |hashtag| - Redis.current.publish("hashtag:#{hashtag}", @payload) - Redis.current.publish("hashtag:#{hashtag}:local", @payload) if status.local? + Redis.current.publish("timeline:hashtag:#{hashtag}", @payload) + Redis.current.publish("timeline:hashtag:#{hashtag}:local", @payload) if status.local? end end def remove_from_public(status) - Redis.current.publish('public', @payload) - Redis.current.publish('public:local', @payload) if status.local? + Redis.current.publish('timeline:public', @payload) + Redis.current.publish('timeline:public:local', @payload) if status.local? end def redis -- cgit