Read the portraits folders once and stop the card pass offline (#77)
The statistics list the portraits folder and its cards subfolder once instead of checking about 340 files. The tall-portrait pass is skipped when the catalog refresh failed and stops at the first network error; the core tells after each attempt whether a portrait was saved, so the worker's throttle can tell the page after any attempt, not only saves. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
485d7b9065
commit
18b06f8ea6
5 files changed
+183
-53
No files matched your search
@@ -244,9 +244,11 @@ impl Tracker {
|
||||
|
||||
/// Downloads the tall card portraits missing from the portraits dir's `cards` folder,
|
||||
/// cropped and shrunk to the card's size (see `process_card_portrait`). A failed
|
||||
/// download or an unreadable image is skipped and retried by the next pass. `on_saved`
|
||||
/// is called after each portrait is saved. Meant to run after `refresh_champions`.
|
||||
pub fn refresh_card_portraits(&self, on_saved: &mut dyn FnMut()) -> Result<(), Error> {
|
||||
/// download of one champion (not found, an unreadable image) is skipped and retried by the
|
||||
/// next pass; a network error stops the pass, as every other request would fail as well.
|
||||
/// `on_attempt` is called after each download attempt, with whether a portrait was saved.
|
||||
/// Meant to run after `refresh_champions`.
|
||||
pub fn refresh_card_portraits(&self, on_attempt: &mut dyn FnMut(bool)) -> Result<(), Error> {
|
||||
let Some((source, portraits_dir)) = &self.champions else {
|
||||
return Ok(());
|
||||
};
|
||||
@@ -259,19 +261,29 @@ impl Tracker {
|
||||
if path.exists() || !champion.key.chars().all(|c| c.is_ascii_alphanumeric()) {
|
||||
continue;
|
||||
}
|
||||
let Ok(art) = source.card_portrait(&champion.key) else {
|
||||
continue;
|
||||
let art = match source.card_portrait(&champion.key) {
|
||||
Ok(art) => art,
|
||||
Err(SourceError::Network(_)) => {
|
||||
on_attempt(false);
|
||||
break;
|
||||
}
|
||||
Err(_) => {
|
||||
on_attempt(false);
|
||||
continue;
|
||||
}
|
||||
};
|
||||
let Ok(card) = process_card_portrait(&art) else {
|
||||
on_attempt(false);
|
||||
continue;
|
||||
};
|
||||
// Written under another name first so a cut write is never taken for a portrait.
|
||||
let partial = path.with_extension("part");
|
||||
if std::fs::write(&partial, card).is_ok() && std::fs::rename(&partial, &path).is_ok() {
|
||||
on_saved();
|
||||
} else {
|
||||
let saved =
|
||||
std::fs::write(&partial, card).is_ok() && std::fs::rename(&partial, &path).is_ok();
|
||||
if !saved {
|
||||
let _ = std::fs::remove_file(&partial);
|
||||
}
|
||||
on_attempt(saved);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user