Fix streamed quoted polls not being hydrated correctly (#37118)

This commit is contained in:
Claire
2025-12-04 15:10:48 +01:00
committed by GitHub
parent 9921fa1af7
commit 88aed3c11a
2 changed files with 40 additions and 19 deletions

View File

@@ -26,12 +26,7 @@ class StatusCacheHydrator
def hydrate_non_reblog_payload(empty_payload, account_id, nested: false)
empty_payload.tap do |payload|
fill_status_payload(payload, @status, account_id, nested:)
if payload[:poll]
payload[:poll][:voted] = @status.account_id == account_id
payload[:poll][:own_votes] = []
end
fill_status_payload(payload, @status, account_id, fresh: !nested, nested:)
end
end
@@ -45,18 +40,7 @@ class StatusCacheHydrator
# used to create the status, we need to hydrate it here too
payload[:reblog][:application] = payload_reblog_application if payload[:reblog][:application].nil? && @status.reblog.account_id == account_id
fill_status_payload(payload[:reblog], @status.reblog, account_id, nested:)
if payload[:reblog][:poll]
if @status.reblog.account_id == account_id
payload[:reblog][:poll][:voted] = true
payload[:reblog][:poll][:own_votes] = []
else
own_votes = PollVote.where(poll_id: @status.reblog.poll_id, account_id: account_id).pluck(:choice)
payload[:reblog][:poll][:voted] = !own_votes.empty?
payload[:reblog][:poll][:own_votes] = own_votes
end
end
fill_status_payload(payload[:reblog], @status.reblog, account_id, fresh: false, nested:)
payload[:filtered] = payload[:reblog][:filtered]
payload[:favourited] = payload[:reblog][:favourited]
@@ -65,7 +49,7 @@ class StatusCacheHydrator
end
end
def fill_status_payload(payload, status, account_id, nested: false)
def fill_status_payload(payload, status, account_id, nested: false, fresh: true)
payload[:favourited] = Favourite.exists?(account_id: account_id, status_id: status.id)
payload[:reblogged] = Status.exists?(account_id: account_id, reblog_of_id: status.id)
payload[:muted] = ConversationMute.exists?(account_id: account_id, conversation_id: status.conversation_id)
@@ -76,6 +60,21 @@ class StatusCacheHydrator
payload[:quote_approval][:current_user] = status.quote_policy_for_account(Account.find_by(id: account_id)) if payload[:quote_approval]
payload[:quote] = hydrate_quote_payload(payload[:quote], status.quote, account_id, nested:) if payload[:quote]
if payload[:poll]
if fresh
# If the status is brand new, we don't need to look up votes in database
payload[:poll][:voted] = status.account_id == account_id
payload[:poll][:own_votes] = []
elsif status.account_id == account_id
payload[:poll][:voted] = true
payload[:poll][:own_votes] = []
else
own_votes = PollVote.where(poll_id: status.poll_id, account_id: account_id).pluck(:choice)
payload[:poll][:voted] = !own_votes.empty?
payload[:poll][:own_votes] = own_votes
end
end
# Nested statuses are more likely to have a stale cache
fill_status_stats(payload, status) if nested
end