mirror of
https://github.com/discourse/discourse.git
synced 2024-12-13 12:43:43 +08:00
983dba37ce
BasicUserSerializer contains enough information for the badges page, while UserSerializer issues ~100 SQL queries on the fly when serializing the field without preloading.
26 lines
560 B
Ruby
26 lines
560 B
Ruby
class DetailedUserBadgeSerializer < BasicUserBadgeSerializer
|
|
has_one :granted_by, serializer: UserBadgeSerializer::UserSerializer
|
|
|
|
attributes :post_number, :topic_id, :topic_title
|
|
|
|
def include_post_number?
|
|
object.post
|
|
end
|
|
|
|
alias :include_topic_id? :include_post_number?
|
|
alias :include_topic_title? :include_post_number?
|
|
|
|
def post_number
|
|
object.post.post_number if object.post
|
|
end
|
|
|
|
def topic_id
|
|
object.post.topic_id if object.post
|
|
end
|
|
|
|
def topic_title
|
|
object.post.topic.title if object.post && object.post.topic
|
|
end
|
|
|
|
end
|