From 9052dfe356a5bce0d93fce6214f77240d81b882d Mon Sep 17 00:00:00 2001 From: Krzysztof Kotlarek Date: Thu, 16 Jul 2020 09:05:11 +1000 Subject: [PATCH] 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. --- .../javascripts/discourse/app/models/post-stream.js | 11 +++++++++-- .../javascripts/discourse/app/widgets/post-gap.js | 4 +++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/discourse/app/models/post-stream.js b/app/assets/javascripts/discourse/app/models/post-stream.js index 2c56f8ef8ae..37b077c9500 100644 --- a/app/assets/javascripts/discourse/app/models/post-stream.js +++ b/app/assets/javascripts/discourse/app/models/post-stream.js @@ -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, diff --git a/app/assets/javascripts/discourse/app/widgets/post-gap.js b/app/assets/javascripts/discourse/app/widgets/post-gap.js index e4ba009147b..481d0efe05e 100644 --- a/app/assets/javascripts/discourse/app/widgets/post-gap.js +++ b/app/assets/javascripts/discourse/app/widgets/post-gap.js @@ -27,6 +27,8 @@ export default createWidget("post-gap", { return this.sendWidgetAction( attrs.pos === "before" ? "fillGapBefore" : "fillGapAfter", args - ); + ).then(() => { + state.loading = false; + }); } });