diff options
author | Vika <vika@fireburn.ru> | 2022-05-10 01:50:11 +0300 |
---|---|---|
committer | Vika <vika@fireburn.ru> | 2022-05-10 01:50:11 +0300 |
commit | 05349fbd7cbeb074ec88a727a52383da99640b37 (patch) | |
tree | 38dc8d23c5a39c2c21e6c380e240e8e3b3c49773 /src/database | |
parent | d38c4ac55ea68ae6dd0262ddd95150b7d46bf93b (diff) | |
download | kittybox-05349fbd7cbeb074ec88a727a52383da99640b37.tar.zst |
FileStorage: fix the item in `after` being emitted as the first
Iterator::skip_while() returns the last item. Reimplement the combinator that I need using a loop over Iterator::by_ref() instead. This will terminate after the end is reached.
Diffstat (limited to 'src/database')
-rw-r--r-- | src/database/file/mod.rs | 19 |
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)) |