Run automatic cache cleanup once after startup preparation
Gitea/pdf-presenter/pipeline/head This commit looks good
Details
Gitea/pdf-presenter/pipeline/head This commit looks good
Details
This commit is contained in:
parent
ae0ff93a8a
commit
9894d6abbe
|
|
@ -2245,7 +2245,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "pdf-presenter"
|
||||
version = "0.1.70"
|
||||
version = "0.1.71"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"chrono",
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ default-members = ["crates/pdf-presenter"]
|
|||
resolver = "3"
|
||||
|
||||
[workspace.package]
|
||||
version = "0.1.70"
|
||||
version = "0.1.71"
|
||||
edition = "2024"
|
||||
license = "MIT"
|
||||
repository = "https://proxy.dandaedre.com/gitea/idle-org/pdf-presenter"
|
||||
|
|
|
|||
|
|
@ -42,8 +42,8 @@ pub fn tr<'a>(ctx: &egui::Context, text: &'a str) -> &'a str {
|
|||
"Disk cache" => "Cache disque",
|
||||
"Maximum total size (MiB)" => "Taille totale maximale (Mio)",
|
||||
"Expire after (days since rendering)" => "Expiration (jours depuis le rendu)",
|
||||
"Oldest files are removed first. Active decks are protected and may exceed the limit. Cleanup runs every minute." => {
|
||||
"Les fichiers les plus anciens sont supprimés en premier. Les présentations actives sont protégées et peuvent dépasser la limite. Nettoyage toutes les minutes."
|
||||
"Oldest files are removed first. Active decks are protected and may exceed the limit. Automatic cleanup runs once at startup, after loading and preparation finish." => {
|
||||
"Les fichiers les plus anciens sont supprimés en premier. Les présentations actives sont protégées et peuvent dépasser la limite. Nettoyage automatique une fois au démarrage, après le chargement et la préparation."
|
||||
}
|
||||
"Expunge unused cache now" => "Purger le cache inutilisé maintenant",
|
||||
"Keep fitted page area when zooming" => {
|
||||
|
|
|
|||
|
|
@ -2347,7 +2347,7 @@ fn menu(ui: &mut Ui, s: &mut Studio) {
|
|||
ui.label(tr(&locale, "Expire after (days since rendering)"));
|
||||
changed |= ui.add(egui::DragValue::new(&mut s.settings.disk_cache.max_days).range(1..=3650)).changed();
|
||||
if changed { s.remember_cache_policy(); }
|
||||
ui.small(tr(&locale, "Oldest files are removed first. Active decks are protected and may exceed the limit. Cleanup runs every minute."));
|
||||
ui.small(tr(&locale, "Oldest files are removed first. Active decks are protected and may exceed the limit. Automatic cleanup runs once at startup, after loading and preparation finish."));
|
||||
if ui.add_enabled(!s.cache_busy && !s.loading && s.initialized, egui::Button::new(tr(&locale, "Expunge unused cache now"))).clicked() { s.clean_cache(true); }
|
||||
ui.small(&s.cache_status);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ pub struct Studio {
|
|||
cache_io: Bridge,
|
||||
pub cache_busy: bool,
|
||||
pub cache_status: String,
|
||||
cache_next: Instant,
|
||||
startup_cache_pending: bool,
|
||||
pub fg: Bridge,
|
||||
pub bg: Bridge,
|
||||
pub io: Bridge,
|
||||
|
|
@ -228,7 +228,7 @@ impl Studio {
|
|||
cache_io: Bridge::with_program(Duration::from_secs(30), worker_program.clone()),
|
||||
cache_busy: false,
|
||||
cache_status: String::new(),
|
||||
cache_next: Instant::now() + Duration::from_secs(60),
|
||||
startup_cache_pending: true,
|
||||
fg: Bridge::with_program(Duration::from_secs(30), worker_program.clone()),
|
||||
bg: Bridge::with_program(Duration::from_secs(30), worker_program.clone()),
|
||||
io,
|
||||
|
|
@ -731,18 +731,17 @@ impl Studio {
|
|||
manual,
|
||||
},
|
||||
) {
|
||||
self.startup_cache_pending = false;
|
||||
self.cache_busy = true;
|
||||
self.cache_status = "Cleaning disk cache…".into();
|
||||
}
|
||||
}
|
||||
pub fn remember_cache_policy(&mut self) {
|
||||
self.save_preferences();
|
||||
self.cache_next = Instant::now() + Duration::from_secs(2);
|
||||
}
|
||||
pub fn poll(&mut self) {
|
||||
while let Ok(c) = self.cache_io.rx.try_recv() {
|
||||
self.cache_busy = false;
|
||||
self.cache_next = Instant::now() + Duration::from_secs(60);
|
||||
self.cache_status = match c.result {
|
||||
Ok(p) => match (p.reply.error, p.reply.cleanup) {
|
||||
(Some(e), _) => format!("Cache cleanup: {e}"),
|
||||
|
|
@ -758,9 +757,6 @@ impl Studio {
|
|||
Err(e) => format!("Cache cleanup: {e}"),
|
||||
};
|
||||
}
|
||||
if Instant::now() >= self.cache_next {
|
||||
self.clean_cache(false);
|
||||
}
|
||||
|
||||
while let Ok(completion) = self.notes_io.rx.try_recv() {
|
||||
if completion.generation != self.generation {
|
||||
|
|
@ -1135,6 +1131,19 @@ impl Studio {
|
|||
self.ram_blocked = false;
|
||||
self.new_output = true;
|
||||
}
|
||||
// One startup pass, after source/notes loading and initial rendering settle.
|
||||
// Prepared disk artifacts count even when the deck exceeds the RAM budget.
|
||||
if self.startup_cache_pending
|
||||
&& self.open_path.is_none()
|
||||
&& self.pending_open.is_none()
|
||||
&& !self.fg_busy
|
||||
&& !self.bg_busy
|
||||
&& !self.notes_pending
|
||||
&& !self.notes_loading
|
||||
&& self.prepared.len() == self.count()
|
||||
{
|
||||
self.clean_cache(false);
|
||||
}
|
||||
}
|
||||
fn schedule(&mut self, page: usize, edge: u32, foreground: bool) {
|
||||
// Reserve both worker slots before admission, including progressive previews.
|
||||
|
|
|
|||
|
|
@ -170,7 +170,7 @@ fn manual_worker_cleanup_preserves_live_document_and_regenerates_after_expunging
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn changed_policy_triggers_background_expiration_and_errors_are_reported() {
|
||||
fn startup_cleanup_runs_once_and_manual_errors_are_reported() {
|
||||
let temp = tempfile::tempdir().unwrap();
|
||||
let root = temp.path().join("cache");
|
||||
let expired = entry(&root, 1, 0, 30, 40);
|
||||
|
|
@ -178,7 +178,6 @@ fn changed_policy_triggers_background_expiration_and_errors_are_reported() {
|
|||
let mut s = Studio::with_program(true, None, env!("CARGO_BIN_EXE_pdf-presenter").into());
|
||||
s.cache_path = root;
|
||||
s.initialized = true;
|
||||
s.remember_cache_policy();
|
||||
let deadline = Instant::now() + Duration::from_secs(10);
|
||||
while !s.cache_status.starts_with("Disk cache:") {
|
||||
s.poll();
|
||||
|
|
@ -187,6 +186,14 @@ fn changed_policy_triggers_background_expiration_and_errors_are_reported() {
|
|||
}
|
||||
assert!(!expired.exists());
|
||||
assert!(fresh.exists());
|
||||
// Neither changing policy nor subsequent polling rearms automatic cleanup.
|
||||
let later = entry(&s.cache_path, 1, 2, 30, 40);
|
||||
s.remember_cache_policy();
|
||||
for _ in 0..20 {
|
||||
s.poll();
|
||||
assert!(!s.cache_busy);
|
||||
}
|
||||
assert!(later.exists());
|
||||
s.cache_path = fresh;
|
||||
s.clean_cache(true);
|
||||
while s.cache_busy {
|
||||
|
|
@ -200,3 +207,43 @@ fn changed_policy_triggers_background_expiration_and_errors_are_reported() {
|
|||
s.cache_status
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn startup_cleanup_waits_for_initial_deck_preparation() {
|
||||
let temp = tempfile::tempdir().unwrap();
|
||||
let images = temp.path().join("images");
|
||||
fs::create_dir(&images).unwrap();
|
||||
for i in 0..8 {
|
||||
common::image(&images.join(format!("{i}.png")), [20, 40, 60, 255]);
|
||||
}
|
||||
let root = temp.path().join("cache");
|
||||
let expired = entry(&root, 1, 0, 30, 40);
|
||||
let mut s = Studio::with_program(
|
||||
true,
|
||||
Some(images),
|
||||
env!("CARGO_BIN_EXE_pdf-presenter").into(),
|
||||
);
|
||||
s.cache_path = root;
|
||||
s.poll();
|
||||
assert!(!s.cache_busy, "Initial open must precede cleanup");
|
||||
assert!(expired.exists());
|
||||
let deadline = Instant::now() + Duration::from_secs(15);
|
||||
while !s.cache_status.starts_with("Disk cache:") {
|
||||
s.poll();
|
||||
if s.cache_busy {
|
||||
assert!(!s.loading && !s.notes_loading);
|
||||
assert_eq!(s.count(), 8);
|
||||
assert_eq!(s.prepared.len(), s.count());
|
||||
// No output acknowledgment is needed for disk preparation completion.
|
||||
assert_eq!(s.output_buffered, 0);
|
||||
}
|
||||
assert!(
|
||||
Instant::now() < deadline,
|
||||
"{} / {}",
|
||||
s.status,
|
||||
s.cache_status
|
||||
);
|
||||
std::thread::sleep(Duration::from_millis(5));
|
||||
}
|
||||
assert!(!expired.exists());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,15 @@
|
|||
|
||||
## Unreleased
|
||||
|
||||
### 0.1.71
|
||||
|
||||
- Run automatic disk-cache cleanup once at startup, after initial document/notes
|
||||
loading and slide preparation finish, instead of every minute. Preferences edits
|
||||
no longer trigger scans; manual expunge remains available. Startup cleanup uses
|
||||
disk preparation completion so decks exceeding the RAM budget are supported.
|
||||
Linux validation passes, including native GUI tests and 84.46% whole-application
|
||||
coverage (75% floor). Windows/macOS checks were not run.
|
||||
|
||||
### 0.1.70
|
||||
|
||||
- Add configurable disk-cache size and lifetime limits (10 GiB / 30 days by
|
||||
|
|
|
|||
|
|
@ -64,11 +64,16 @@ do not extend lifetime. Future timestamps do not expire until their age reaches
|
|||
the limit. Expired files are removed first in oldest-first order, then older files
|
||||
are removed until total bytes are within the target. Ties sort by path.
|
||||
|
||||
A dedicated killable worker starts maintenance 60 seconds after startup and repeats
|
||||
60 seconds after completion; option changes schedule it after two seconds. Loading
|
||||
a document defers submission. Cleanup never blocks first-page display or UI input.
|
||||
Since 0.1.71, a dedicated killable worker runs automatic maintenance once per launch,
|
||||
after settings and any initial document/notes loading and slide preparation finish.
|
||||
Rolling-buffer decks need all slides prepared on disk, not resident in RAM. With no
|
||||
document, cleanup runs after startup settings load. Incomplete/failed slide preparation
|
||||
defers automatic cleanup; manual expunge remains available. Later document opens and
|
||||
option changes do not schedule another pass. New limits apply on the next startup;
|
||||
manual expunge is immediate. Cleanup never blocks first-page display or UI input.
|
||||
Only one cleanup request is admitted per presenter; its deadline is 30 seconds.
|
||||
Errors/timeouts appear in the Disk cache section and retry on the next interval.
|
||||
Errors/timeouts appear in the Disk cache section without automatic retries.
|
||||
A manual request also consumes any pending startup pass, avoiding duplicate work.
|
||||
Manual cleanup reports removed files/bytes, remaining bytes and retained candidates.
|
||||
Counts are a scan snapshot; concurrent rendering can change actual usage.
|
||||
|
||||
|
|
|
|||
|
|
@ -388,8 +388,10 @@ output. It cannot predict compositor/hardware delays or guarantee a frame rate.
|
|||
### Disk cache cleanup
|
||||
|
||||
In **Menu → Preferences → Disk cache**, set the maximum total size in MiB and
|
||||
lifetime in days since rendering (defaults: 10 GiB and 30 days). Cleanup runs every
|
||||
minute, deleting expired files and then the oldest files to meet the size target.
|
||||
lifetime in days since rendering (defaults: 10 GiB and 30 days). Automatic cleanup runs once at startup, after initial document loading and slide
|
||||
preparation complete, deleting expired files and then the oldest files to meet the
|
||||
size target. Changing limits takes effect at the next startup; manual expunge remains
|
||||
available immediately.
|
||||
**Expunge unused cache now** clears eligible cached slides immediately in the
|
||||
background. Active decks are protected and may temporarily exceed either limit.
|
||||
The cleanup report shows removed and remaining data; deleted slides regenerate
|
||||
|
|
|
|||
Loading…
Reference in New Issue