about summary refs log tree commit diff
path: root/src/database
diff options
context:
space:
mode:
Diffstat (limited to 'src/database')
-rw-r--r--src/database/file/mod.rs19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/database/file/mod.rs b/src/database/file/mod.rs
index 031527e..4a40f38 100644
--- a/src/database/file/mod.rs
+++ b/src/database/file/mod.rs
@@ -484,16 +484,19 @@ impl Storage for FileStorage {
             if let Some(mut feed) = filter_post(feed, user) {
                 if feed["children"].is_array() {
                     let children = feed["children"].as_array().unwrap().clone();
-                    let posts_iter = children
+                    let mut posts_iter = children
                         .into_iter()
-                        .map(|s: serde_json::Value| s.as_str().unwrap().to_string())
-                        .skip_while(|s: &String| {
-                            if let Some(after) = after {
-                                s != after
-                            } else {
-                                false
+                        .map(|s: serde_json::Value| s.as_str().unwrap().to_string());
+                    // Note: we can't actually use skip_while here because we end up emitting `after`.
+                    // This imperative snippet consumes after instead of emitting it, allowing the
+                    // stream of posts to return only those items that truly come *after*.
+                    if let Some(after) = after {
+                        for s in posts_iter.by_ref() {
+                            if &s != after {
+                                break
                             }
-                        });
+                        }
+                    };
                     let posts = stream::iter(posts_iter)
                         .map(|url: String| async move { self.get_post(&url).await })
                         .buffered(std::cmp::min(3, limit))