From 05349fbd7cbeb074ec88a727a52383da99640b37 Mon Sep 17 00:00:00 2001 From: Vika Date: Tue, 10 May 2022 01:50:11 +0300 Subject: 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. --- src/database/file/mod.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'src/database/file') 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)) -- cgit 1.4.1