FEATURE: load hidden posts in segments (#10240)

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.

diff --git a/app/assets/javascripts/discourse/app/models/post-stream.js b/app/assets/javascripts/discourse/app/models/post-stream.js
index 2c56f8e..37b077c 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 e4ba009..481d0ef 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;
+    });
   }
 });

GitHub sha: 9052dfe3

1 Like

This commit appears in #10240 which was merged by lis2.