grab highest post number from the raw data, so deletions at the end of a topic work

This commit is contained in:
Sam Saffron 2013-02-15 12:58:14 +11:00
parent 9eb5c2a66a
commit a8085f15c4
3 changed files with 19 additions and 4 deletions

View file

@ -5,7 +5,6 @@ class TopicViewSerializer < ApplicationSerializer
[:id,
:title,
:posts_count,
:highest_post_number,
:created_at,
:views,
:reply_count,
@ -41,7 +40,8 @@ class TopicViewSerializer < ApplicationSerializer
:notification_level,
:notifications_reason_id,
:posts,
:at_bottom
:at_bottom,
:highest_post_number
has_one :created_by, serializer: BasicUserSerializer, embed: :objects
has_one :last_poster, serializer: BasicUserSerializer, embed: :objects
@ -185,7 +185,11 @@ class TopicViewSerializer < ApplicationSerializer
# Whether we're at the bottom of a topic (last page)
def at_bottom
posts.present? and (@highest_number_in_posts == object.topic.highest_post_number)
posts.present? and (@highest_number_in_posts == object.highest_post_number)
end
def highest_post_number
object.highest_post_number
end
def posts

View file

@ -223,6 +223,15 @@ class TopicView
@suggested_topics ||= TopicQuery.new(@user).list_suggested_for(topic)
end
# This is pending a larger refactor, that allows custom orders
# for now we need to look for the highest_post_number in the stream
# the cache on topics is not correct if there are deleted posts at
# the end of the stream (for mods), nor is it correct for filtered
# streams
def highest_post_number
@highest_post_number ||= @posts.maximum(:post_number)
end
protected
def read_posts_set

View file

@ -106,10 +106,12 @@ describe TopicView do
end
it 'allows admins to see deleted posts' do
post_number = p3.post_number
p3.destroy
admin = Fabricate(:admin)
topic_view = TopicView.new(topic.id, admin)
topic_view.posts.count.should == 3
topic_view.highest_post_number.should == post_number
end
it 'does not allow non admins to see deleted posts' do
@ -117,7 +119,7 @@ describe TopicView do
topic_view.posts.count.should == 2
end
# Sam: disabled for now, we only need this for poss, if we do, roll it into topic
# Sam: disabled for now, we only need this for polls, if we do, roll it into topic
# having to walk every post action is not really a good idea
#
# context '.voted_in_topic?' do