Allow bulk updates with a limit and starting point

This commit is contained in:
mtkennerly 2023-12-18 00:28:16 +08:00
parent 06b2c877f0
commit e5a5cd4739
No known key found for this signature in database
GPG key ID: E764BE00BE6E6408
3 changed files with 49 additions and 11 deletions

View file

@ -256,10 +256,23 @@ impl WikiCache {
Ok(())
}
pub async fn refresh(&mut self, outdated_only: bool, titles: Option<Vec<String>>) -> Result<(), Error> {
pub async fn refresh(
&mut self,
outdated_only: bool,
titles: Option<Vec<String>>,
limit: Option<usize>,
from: Option<String>,
) -> Result<(), Error> {
let mut i = 0;
let solo = titles.is_some();
let titles: Vec<_> = titles.unwrap_or_else(|| self.0.keys().cloned().collect());
let titles: Vec<_> = titles.unwrap_or_else(|| {
self.0
.keys()
.skip_while(|x| from.as_ref().is_some_and(|from| from != *x))
.take(limit.unwrap_or(usize::MAX))
.cloned()
.collect()
});
for title in &titles {
let cached = self.0.get(title).cloned().unwrap_or_default();