Unify some refresh logic

This commit is contained in:
mtkennerly 2023-12-18 00:33:49 +08:00
parent e5a5cd4739
commit b35178d59d
No known key found for this signature in database
GPG key ID: E764BE00BE6E6408

View file

@ -267,18 +267,16 @@ impl WikiCache {
let solo = titles.is_some();
let titles: Vec<_> = titles.unwrap_or_else(|| {
self.0
.keys()
.skip_while(|x| from.as_ref().is_some_and(|from| from != *x))
.iter()
.filter(|(_, v)| !outdated_only || v.state == State::Outdated)
.skip_while(|(k, _)| from.as_ref().is_some_and(|from| from != *k))
.take(limit.unwrap_or(usize::MAX))
.cloned()
.map(|(k, _)| k.to_string())
.collect()
});
for title in &titles {
let cached = self.0.get(title).cloned().unwrap_or_default();
if outdated_only && cached.state != State::Outdated {
continue;
}
println!("Wiki: {}", title);
let latest = WikiCacheEntry::fetch_from_page(title.clone()).await;