mirror of
https://github.com/discourse/discourse.git
synced 2024-12-25 23:03:43 +08:00
9b0300a647
These fields are often used when serializing topics which may contain multiple polls. On average, serializing a poll took 2+N queries where N is the number of options. This change reduces the number of queries to 3, one for each field (Poll#voters_count, PollOption#voters_count and Poll#has_voted?).
18 lines
281 B
Ruby
18 lines
281 B
Ruby
# frozen_string_literal: true
|
|
|
|
class PollOptionSerializer < ApplicationSerializer
|
|
attributes :id, :html, :votes
|
|
|
|
def id
|
|
object.digest
|
|
end
|
|
|
|
def votes
|
|
object.voters_count + object.anonymous_votes.to_i
|
|
end
|
|
|
|
def include_votes?
|
|
scope[:can_see_results]
|
|
end
|
|
end
|