DEV: Remove `TopicView#first_post_id`. (#14631)
The method was only used for mega topics but it was redundant as the first post can be determined from using the condition where `Post#post_number` equal to one.
This commit is contained in:
parent
b69c2f7311
commit
fb5a062b1f
|
@ -100,24 +100,19 @@ export default RestModel.extend({
|
|||
canAppendMore: and("notLoading", "hasPosts", "lastPostNotLoaded"),
|
||||
canPrependMore: and("notLoading", "hasPosts", "firstPostNotLoaded"),
|
||||
|
||||
@discourseComputed("hasLoadedData", "firstPostId", "posts.[]")
|
||||
firstPostPresent(hasLoadedData, firstPostId) {
|
||||
@discourseComputed("hasLoadedData", "posts.[]")
|
||||
firstPostPresent(hasLoadedData) {
|
||||
if (!hasLoadedData) {
|
||||
return false;
|
||||
}
|
||||
return !!this.posts.findBy("id", firstPostId);
|
||||
|
||||
return !!this.posts.findBy("post_number", 1);
|
||||
},
|
||||
|
||||
firstPostNotLoaded: not("firstPostPresent"),
|
||||
|
||||
firstId: null,
|
||||
lastId: null,
|
||||
|
||||
@discourseComputed("isMegaTopic", "stream.firstObject", "firstId")
|
||||
firstPostId(isMegaTopic, streamFirstId, firstId) {
|
||||
return isMegaTopic ? firstId : streamFirstId;
|
||||
},
|
||||
|
||||
@discourseComputed("isMegaTopic", "stream.lastObject", "lastId")
|
||||
lastPostId(isMegaTopic, streamLastId, lastId) {
|
||||
return isMegaTopic ? lastId : streamLastId;
|
||||
|
|
|
@ -44,7 +44,6 @@ module("Unit | Model | post-stream", function () {
|
|||
const postStream = buildStream(4567, [1, 3, 4]);
|
||||
const store = postStream.store;
|
||||
|
||||
assert.equal(postStream.get("firstPostId"), 1);
|
||||
assert.equal(postStream.get("lastPostId"), 4, "the last post id is 4");
|
||||
|
||||
assert.ok(!postStream.get("hasPosts"), "there are no posts by default");
|
||||
|
@ -1042,19 +1041,6 @@ module("Unit | Model | post-stream", function () {
|
|||
assert.equal(postStream.get("filteredPostsCount"), 4);
|
||||
});
|
||||
|
||||
test("firstPostId", function (assert) {
|
||||
const postStream = buildStream(4567, [1, 3, 4]);
|
||||
|
||||
assert.equal(postStream.get("firstPostId"), 1);
|
||||
|
||||
postStream.setProperties({
|
||||
isMegaTopic: true,
|
||||
firstId: 2,
|
||||
});
|
||||
|
||||
assert.equal(postStream.get("firstPostId"), 2);
|
||||
});
|
||||
|
||||
test("lastPostId", function (assert) {
|
||||
const postStream = buildStream(4567, [1, 3, 4]);
|
||||
|
||||
|
|
|
@ -22,7 +22,6 @@ module PostStreamSerializerMixin
|
|||
result[:stream] = object.filtered_post_ids
|
||||
else
|
||||
result[:isMegaTopic] = true
|
||||
result[:firstId] = object.first_post_id
|
||||
result[:lastId] = object.last_post_id
|
||||
end
|
||||
end
|
||||
|
|
|
@ -631,10 +631,6 @@ class TopicView
|
|||
@is_mega_topic ||= (@topic.posts_count >= MEGA_TOPIC_POSTS_COUNT)
|
||||
end
|
||||
|
||||
def first_post_id
|
||||
@filtered_posts.order(sort_order: :asc).pluck_first(:id)
|
||||
end
|
||||
|
||||
def last_post_id
|
||||
@filtered_posts.order(sort_order: :desc).pluck_first(:id)
|
||||
end
|
||||
|
|
|
@ -839,7 +839,7 @@ describe TopicView do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#first_post_id and #last_post_id' do
|
||||
describe '#last_post_id' do
|
||||
let!(:p3) { Fabricate(:post, topic: topic) }
|
||||
let!(:p2) { Fabricate(:post, topic: topic) }
|
||||
let!(:p1) { Fabricate(:post, topic: topic) }
|
||||
|
@ -851,7 +851,6 @@ describe TopicView do
|
|||
end
|
||||
|
||||
it 'should return the right id' do
|
||||
expect(topic_view.first_post_id).to eq(p1.id)
|
||||
expect(topic_view.last_post_id).to eq(p3.id)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue