mirror of
https://github.com/discourse/discourse.git
synced 2025-02-13 14:55:06 +00:00
Rename posts_count
in topic view to post_counts_by_user
which makes much more sense
This commit is contained in:
parent
2efd3e61c7
commit
5dc47c2d82
@ -172,11 +172,11 @@ class TopicViewSerializer < ApplicationSerializer
|
|||||||
end
|
end
|
||||||
|
|
||||||
def participants
|
def participants
|
||||||
object.posts_count.collect {|tuple| {user: object.participants[tuple.first], post_count: tuple[1]}}
|
object.post_counts_by_user.collect {|tuple| {user: object.participants[tuple.first], post_count: tuple[1]}}
|
||||||
end
|
end
|
||||||
|
|
||||||
def include_participants?
|
def include_participants?
|
||||||
object.initial_load? && object.posts_count.present?
|
object.initial_load? && object.post_counts_by_user.present?
|
||||||
end
|
end
|
||||||
|
|
||||||
def suggested_topics
|
def suggested_topics
|
||||||
|
@ -4,7 +4,11 @@ require_dependency 'summarize'
|
|||||||
|
|
||||||
class TopicView
|
class TopicView
|
||||||
|
|
||||||
attr_accessor :topic, :draft, :draft_key, :draft_sequence, :posts
|
attr_accessor :topic,
|
||||||
|
:draft,
|
||||||
|
:draft_key,
|
||||||
|
:draft_sequence,
|
||||||
|
:posts
|
||||||
|
|
||||||
def initialize(topic_id, user=nil, options={})
|
def initialize(topic_id, user=nil, options={})
|
||||||
@topic = find_topic(topic_id)
|
@topic = find_topic(topic_id)
|
||||||
@ -169,14 +173,14 @@ class TopicView
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def posts_count
|
def post_counts_by_user
|
||||||
@posts_count ||= Post.where(topic_id: @topic.id).group(:user_id).order('count_all desc').limit(24).count
|
@post_counts_by_user ||= Post.where(topic_id: @topic.id).group(:user_id).order('count_all desc').limit(24).count
|
||||||
end
|
end
|
||||||
|
|
||||||
def participants
|
def participants
|
||||||
@participants ||= begin
|
@participants ||= begin
|
||||||
participants = {}
|
participants = {}
|
||||||
User.where(id: posts_count.map {|k,v| k}).each {|u| participants[u.id] = u}
|
User.where(id: post_counts_by_user.map {|k,v| k}).each {|u| participants[u.id] = u}
|
||||||
participants
|
participants
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -94,9 +94,9 @@ describe TopicView do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context '.posts_count' do
|
context '.post_counts_by_user' do
|
||||||
it 'returns the two posters with their counts' do
|
it 'returns the two posters with their counts' do
|
||||||
topic_view.posts_count.to_a.should =~ [[first_poster.id, 2], [coding_horror.id, 1]]
|
topic_view.post_counts_by_user.to_a.should =~ [[first_poster.id, 2], [coding_horror.id, 1]]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user