about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorVika <vika@fireburn.ru>2022-05-10 01:36:00 +0300
committerVika <vika@fireburn.ru>2022-05-10 01:36:00 +0300
commit1648c476a1d3d8f56daf09840baaddeb5967c5ed (patch)
treecb4815bf1ce30ac2f2f023a8da7cdc08eee738ee /src
parentd95ae14555b421eb62f9ffaeb7c869c540961fa4 (diff)
downloadkittybox-1648c476a1d3d8f56daf09840baaddeb5967c5ed.tar.zst
FileStorage: fix the hang when "after" isn't listed in the feed
Closes #4.
Diffstat (limited to 'src')
-rw-r--r--src/database/file/mod.rs17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/database/file/mod.rs b/src/database/file/mod.rs
index 853240a..64d9564 100644
--- a/src/database/file/mod.rs
+++ b/src/database/file/mod.rs
@@ -489,17 +489,16 @@ 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 mut posts_iter = children
+                    let posts_iter = children
                         .into_iter()
-                        .map(|s: serde_json::Value| s.as_str().unwrap().to_string());
-                    if after.is_some() {
-                        loop {
-                            let i = posts_iter.next();
-                            if &i == after {
-                                break;
+                        .map(|s: serde_json::Value| s.as_str().unwrap().to_string())
+                        .skip_while(|s: &String| {
+                            if let Some(after) = after {
+                                s != after
+                            } else {
+                                false
                             }
-                        }
-                    }
+                        });
                     let posts = stream::iter(posts_iter)
                         .map(|url: String| async move { self.get_post(&url).await })
                         .buffered(std::cmp::min(3, limit))