mirror of
https://github.com/discourse/discourse.git
synced 2025-03-29 02:55:44 +08:00
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"),
|
canAppendMore: and("notLoading", "hasPosts", "lastPostNotLoaded"),
|
||||||
canPrependMore: and("notLoading", "hasPosts", "firstPostNotLoaded"),
|
canPrependMore: and("notLoading", "hasPosts", "firstPostNotLoaded"),
|
||||||
|
|
||||||
@discourseComputed("hasLoadedData", "firstPostId", "posts.[]")
|
@discourseComputed("hasLoadedData", "posts.[]")
|
||||||
firstPostPresent(hasLoadedData, firstPostId) {
|
firstPostPresent(hasLoadedData) {
|
||||||
if (!hasLoadedData) {
|
if (!hasLoadedData) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return !!this.posts.findBy("id", firstPostId);
|
|
||||||
|
return !!this.posts.findBy("post_number", 1);
|
||||||
},
|
},
|
||||||
|
|
||||||
firstPostNotLoaded: not("firstPostPresent"),
|
firstPostNotLoaded: not("firstPostPresent"),
|
||||||
|
|
||||||
firstId: null,
|
|
||||||
lastId: null,
|
lastId: null,
|
||||||
|
|
||||||
@discourseComputed("isMegaTopic", "stream.firstObject", "firstId")
|
|
||||||
firstPostId(isMegaTopic, streamFirstId, firstId) {
|
|
||||||
return isMegaTopic ? firstId : streamFirstId;
|
|
||||||
},
|
|
||||||
|
|
||||||
@discourseComputed("isMegaTopic", "stream.lastObject", "lastId")
|
@discourseComputed("isMegaTopic", "stream.lastObject", "lastId")
|
||||||
lastPostId(isMegaTopic, streamLastId, lastId) {
|
lastPostId(isMegaTopic, streamLastId, lastId) {
|
||||||
return isMegaTopic ? lastId : streamLastId;
|
return isMegaTopic ? lastId : streamLastId;
|
||||||
|
@ -44,7 +44,6 @@ module("Unit | Model | post-stream", function () {
|
|||||||
const postStream = buildStream(4567, [1, 3, 4]);
|
const postStream = buildStream(4567, [1, 3, 4]);
|
||||||
const store = postStream.store;
|
const store = postStream.store;
|
||||||
|
|
||||||
assert.equal(postStream.get("firstPostId"), 1);
|
|
||||||
assert.equal(postStream.get("lastPostId"), 4, "the last post id is 4");
|
assert.equal(postStream.get("lastPostId"), 4, "the last post id is 4");
|
||||||
|
|
||||||
assert.ok(!postStream.get("hasPosts"), "there are no posts by default");
|
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);
|
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) {
|
test("lastPostId", function (assert) {
|
||||||
const postStream = buildStream(4567, [1, 3, 4]);
|
const postStream = buildStream(4567, [1, 3, 4]);
|
||||||
|
|
||||||
|
@ -22,7 +22,6 @@ module PostStreamSerializerMixin
|
|||||||
result[:stream] = object.filtered_post_ids
|
result[:stream] = object.filtered_post_ids
|
||||||
else
|
else
|
||||||
result[:isMegaTopic] = true
|
result[:isMegaTopic] = true
|
||||||
result[:firstId] = object.first_post_id
|
|
||||||
result[:lastId] = object.last_post_id
|
result[:lastId] = object.last_post_id
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -631,10 +631,6 @@ class TopicView
|
|||||||
@is_mega_topic ||= (@topic.posts_count >= MEGA_TOPIC_POSTS_COUNT)
|
@is_mega_topic ||= (@topic.posts_count >= MEGA_TOPIC_POSTS_COUNT)
|
||||||
end
|
end
|
||||||
|
|
||||||
def first_post_id
|
|
||||||
@filtered_posts.order(sort_order: :asc).pluck_first(:id)
|
|
||||||
end
|
|
||||||
|
|
||||||
def last_post_id
|
def last_post_id
|
||||||
@filtered_posts.order(sort_order: :desc).pluck_first(:id)
|
@filtered_posts.order(sort_order: :desc).pluck_first(:id)
|
||||||
end
|
end
|
||||||
|
@ -839,7 +839,7 @@ describe TopicView do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#first_post_id and #last_post_id' do
|
describe '#last_post_id' do
|
||||||
let!(:p3) { Fabricate(:post, topic: topic) }
|
let!(:p3) { Fabricate(:post, topic: topic) }
|
||||||
let!(:p2) { Fabricate(:post, topic: topic) }
|
let!(:p2) { Fabricate(:post, topic: topic) }
|
||||||
let!(:p1) { Fabricate(:post, topic: topic) }
|
let!(:p1) { Fabricate(:post, topic: topic) }
|
||||||
@ -851,7 +851,6 @@ describe TopicView do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it 'should return the right id' do
|
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)
|
expect(topic_view.last_post_id).to eq(p3.id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user