Add caching for payload serialization during fan-out (#19642)

This commit is contained in:
Eugen Rochko
2022-11-04 13:21:06 +01:00
committed by GitHub
parent b8f6f03956
commit 5f9e47be34
5 changed files with 129 additions and 7 deletions

View File

@ -14,6 +14,7 @@ class FanOutOnWriteService < BaseService
@options = options
check_race_condition!
warm_payload_cache!
fan_out_to_local_recipients!
fan_out_to_public_recipients! if broadcastable?
@ -135,13 +136,21 @@ class FanOutOnWriteService < BaseService
AccountConversation.add_status(@account, @status) unless update?
end
def warm_payload_cache!
Rails.cache.write("fan-out/#{@status.id}", rendered_status)
end
def anonymous_payload
@anonymous_payload ||= Oj.dump(
event: update? ? :'status.update' : :update,
payload: InlineRenderer.render(@status, nil, :status)
payload: rendered_status
)
end
def rendered_status
@rendered_status ||= InlineRenderer.render(@status, nil, :status)
end
def update?
@options[:update]
end