FEATURE: load hidden posts in segments (#10240)

* FEATURE: load hidden posts in segments

Currently, when "View hidden replies" button is clicked, all replies are loaded like there is no tomorrow. When there is plenty of hidden replies, it may cause a timeout.

Therefore, we should load them in pages and display the view link as long as we have more hidden replies.
This commit is contained in:
Krzysztof Kotlarek 2020-07-16 09:05:11 +10:00 committed by GitHub
parent 34bbd51350
commit 9052dfe356
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 3 deletions

View File

@ -304,8 +304,11 @@ export default RestModel.extend({
let postIdx = currentPosts.indexOf(post);
const origIdx = postIdx;
let headGap = gap.slice(0, this.topic.chunk_size);
let tailGap = gap.slice(this.topic.chunk_size);
if (postIdx !== -1) {
return this.findPostsByIds(gap).then(posts => {
return this.findPostsByIds(headGap).then(posts => {
posts.forEach(p => {
const stored = this.storePost(p);
if (!currentPosts.includes(stored)) {
@ -313,7 +316,11 @@ export default RestModel.extend({
}
});
delete this.get("gaps.before")[postId];
if (tailGap.length > 0) {
this.get("gaps.before")[postId] = tailGap;
} else {
delete this.get("gaps.before")[postId];
}
this.stream.arrayContentDidChange();
this.postsWithPlaceholders.arrayContentDidChange(
origIdx,

View File

@ -27,6 +27,8 @@ export default createWidget("post-gap", {
return this.sendWidgetAction(
attrs.pos === "before" ? "fillGapBefore" : "fillGapAfter",
args
);
).then(() => {
state.loading = false;
});
}
});