0
0
Fork 0

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
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 129 additions and 7 deletions

View file

@ -5,11 +5,12 @@ class PushUpdateWorker
include Redisable
def perform(account_id, status_id, timeline_id = nil, options = {})
@account = Account.find(account_id)
@status = Status.includes(active_mentions: :account, reblog: { active_mentions: :account }).find(status_id)
@timeline_id = timeline_id || "timeline:#{account.id}"
@status = Status.find(status_id)
@account_id = account_id
@timeline_id = timeline_id || "timeline:#{account_id}"
@options = options.symbolize_keys
render_payload!
publish!
rescue ActiveRecord::RecordNotFound
true
@ -17,14 +18,14 @@ class PushUpdateWorker
private
def payload
InlineRenderer.render(@status, @account, :status)
def render_payload!
@payload = StatusCacheHydrator.new(@status).hydrate(@account_id)
end
def message
Oj.dump(
event: update? ? :'status.update' : :update,
payload: payload,
payload: @payload,
queued_at: (Time.now.to_f * 1000.0).to_i
)
end