Replace calls to FeedManager#inline_render and #broadcast

This commit is contained in:
Eugen Rochko 2017-04-05 19:45:18 +02:00
parent d755ce96da
commit 5b95be1c42
6 changed files with 26 additions and 20 deletions

View File

@ -34,7 +34,7 @@ class FeedManager
trim(timeline_type, account.id) trim(timeline_type, account.id)
end end
PushUpdateWorker.perform_async(timeline_type, account.id, status.id) PushUpdateWorker.perform_async(account.id, status.id)
end end
def trim(type, account_id) def trim(type, account_id)

View File

@ -0,0 +1,13 @@
# frozen_string_literal: true
class InlineRenderer
def self.render(status, current_account, template)
Rabl::Renderer.new(
template,
status,
view_path: 'app/views',
format: :json,
scope: InlineRablScope.new(current_account)
).render
end
end

View File

@ -50,22 +50,22 @@ class FanOutOnWriteService < BaseService
end end
def render_anonymous_payload(status) 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 end
def deliver_to_hashtags(status) def deliver_to_hashtags(status)
Rails.logger.debug "Delivering status #{status.id} to hashtags" Rails.logger.debug "Delivering status #{status.id} to hashtags"
status.tags.pluck(:name).each do |hashtag| status.tags.pluck(:name).each do |hashtag|
FeedManager.instance.broadcast("hashtag:#{hashtag}", event: 'update', payload: @payload) Redis.current.publish("hashtag:#{hashtag}", Oj.dump(event: :update, payload: @payload))
FeedManager.instance.broadcast("hashtag:#{hashtag}:local", event: 'update', payload: @payload) if status.account.local? Redis.current.publish("hashtag:#{hashtag}:local", Oj.dump(event: :update, payload: @payload)) if status.account.local?
end end
end end
def deliver_to_public(status) def deliver_to_public(status)
Rails.logger.debug "Delivering status #{status.id} to public timeline" Rails.logger.debug "Delivering status #{status.id} to public timeline"
FeedManager.instance.broadcast(:public, event: 'update', payload: @payload) Redis.current.publish('public', Oj.dump(event: 'update', payload: @payload))
FeedManager.instance.broadcast('public:local', event: 'update', payload: @payload) if status.account.local? Redis.current.publish('public:local', Oj.dump(event: 'update', payload: @payload)) if status.account.local?
end end
end end

View File

@ -50,7 +50,7 @@ class NotifyService < BaseService
def create_notification def create_notification
@notification.save! @notification.save!
return unless @notification.browserable? return unless @notification.browserable?
FeedManager.instance.broadcast(@recipient.id, event: 'notification', payload: FeedManager.instance.inline_render(@recipient, 'api/v1/notifications/show', @notification)) Redis.current.publish(@recipient.id, Oj.dump(event: :notification, payload: InlineRenderer.render(@notification, @recipient, 'api/v1/notifications/show')))
end end
def send_email def send_email

View File

@ -65,17 +65,17 @@ class RemoveStatusService < BaseService
redis.zremrangebyscore(FeedManager.instance.key(type, receiver.id), status.id, status.id) redis.zremrangebyscore(FeedManager.instance.key(type, receiver.id), status.id, status.id)
end end
FeedManager.instance.broadcast(receiver.id, event: 'delete', payload: status.id) Redis.current.publish(receiver.id, Oj.dump(event: :delete, payload: status.id))
end end
def remove_from_hashtags(status) def remove_from_hashtags(status)
status.tags.each do |tag| status.tags.each do |tag|
FeedManager.instance.broadcast("hashtag:#{tag.name}", event: 'delete', payload: status.id) Redis.current.publish("hashtag:#{tag.name}", Oj.dump(event: :delete, payload: status.id))
end end
end end
def remove_from_public(status) def remove_from_public(status)
FeedManager.instance.broadcast(:public, event: 'delete', payload: status.id) Redis.current.publish('public', Oj.dump(event: :delete, payload: status.id))
end end
def redis def redis

View File

@ -3,19 +3,12 @@
class PushUpdateWorker class PushUpdateWorker
include Sidekiq::Worker include Sidekiq::Worker
def perform(timeline, account_id, status_id) def perform(account_id, status_id)
account = Account.find(account_id) account = Account.find(account_id)
status = Status.find(status_id) status = Status.find(status_id)
message = InlineRenderer.render(status, account, 'api/v1/statuses/show')
message = Rabl::Renderer.new( Redis.current.publish("timeline:#{account.id}", Oj.dump(event: :update, payload: message, queued_at: (Time.now.to_f * 1000.0).to_i))
'api/v1/statuses/show',
status,
view_path: 'app/views',
format: :json,
scope: InlineRablScope.new(account)
)
Redis.current.publish("timeline:#{account.id}", Oj.dump({ event: :update, payload: message, queued_at: (Time.now.to_f * 1000.0).to_i }))
rescue ActiveRecord::RecordNotFound rescue ActiveRecord::RecordNotFound
true true
end end