Rename TopicView#last_read_post_id to TopicView#filtered_post_id.

This commit is contained in:
Guo Xiang Tan 2018-06-27 12:33:57 +08:00
parent cb69888758
commit cfa7898c2d
3 changed files with 10 additions and 10 deletions

View File

@ -187,7 +187,7 @@ class TopicViewSerializer < ApplicationSerializer
def last_read_post_id
return nil unless last_read_post_number
object.last_read_post_id(last_read_post_number)
object.filtered_post_id(last_read_post_number)
end
alias_method :include_last_read_post_id?, :has_topic_user?

View File

@ -412,7 +412,7 @@ class TopicView
end
end
def last_read_post_id(post_number)
def filtered_post_id(post_number)
@filtered_posts.where(post_number: post_number).pluck(:id).first
end
@ -566,16 +566,16 @@ class TopicView
def closest_post_to(post_number)
# happy path
closest_post = @filtered_posts.where("post_number = ?", post_number).limit(1).pluck(:id)
closest_post_id = filtered_post_id(post_number)
if closest_post.empty?
if closest_post_id.blank?
# less happy path, missing post
closest_post = @filtered_posts.order("@(post_number - #{post_number})").limit(1).pluck(:id)
closest_post_id = @filtered_posts.order("@(post_number - #{post_number})").limit(1).pluck(:id).first
end
return nil if closest_post.empty?
return nil if closest_post_id.blank?
filtered_post_ids.index(closest_post.first) || filtered_post_ids[0]
filtered_post_ids.index(closest_post_id) || filtered_post_ids[0]
end
MEGA_TOPIC_POSTS_COUNT = 10000

View File

@ -583,12 +583,12 @@ describe TopicView do
end
end
describe '#last_read_post_id' do
describe '#filtered_post_id' do
it 'should return the right id' do
post = Fabricate(:post, topic: topic)
expect(topic_view.last_read_post_id(nil)).to eq(nil)
expect(topic_view.last_read_post_id(post.post_number)).to eq(post.id)
expect(topic_view.filtered_post_id(nil)).to eq(nil)
expect(topic_view.filtered_post_id(post.post_number)).to eq(post.id)
end
end
end