From 1648c476a1d3d8f56daf09840baaddeb5967c5ed Mon Sep 17 00:00:00 2001 From: Vika Date: Tue, 10 May 2022 01:36:00 +0300 Subject: FileStorage: fix the hang when "after" isn't listed in the feed Closes #4. --- src/database/file/mod.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'src/database') 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)) -- cgit 1.4.1