From faf52f6dbdc591ffdceda034c6ae42184c3a8df4 Mon Sep 17 00:00:00 2001 From: Duncan Tourolle Date: Sat, 26 Sep 2026 12:34:54 -0400 Subject: [PATCH] Ask the prefetch's cache questions on one held connection holds_original, the prefetch worker's check that a neighbour's original is already cached, opened the catalog for every neighbour it asked about. Its own comment called it a row check; the open around it was four of the five opens a develop landing made. The worker now keeps one Catalog for the batch it is serving, opened at the first check and reopened only if the batch names another catalog file. The connection runs in autocommit, so each check still sees what fetch_original committed in between. fetch_original is unchanged. With the backfill no longer run on every open, a landing whose neighbours are all cached goes from five opens to two, and from ~80 ms of CPU to ~1-2 ms on a copy of the reference catalog. --- ui/dr-ui/src/library/thumbnails_fetch.rs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/ui/dr-ui/src/library/thumbnails_fetch.rs b/ui/dr-ui/src/library/thumbnails_fetch.rs index 92c3603..1b9479f 100644 --- a/ui/dr-ui/src/library/thumbnails_fetch.rs +++ b/ui/dr-ui/src/library/thumbnails_fetch.rs @@ -890,6 +890,9 @@ pub(super) fn serve_prefetches(shared: &PrefetchShared, events: &Sender bool { +/// +/// Asked on `held`, which the caller keeps across a batch of these: a +/// connection per question was an open per prefetched neighbour, four of the +/// five a develop landing made. Opened here on first use, and again only if +/// the batch moves to another catalog. +pub(super) fn holds_original(cache: &CacheContext, held: &mut Option<(PathBuf, Catalog)>) -> bool { let Ok(store) = dr_catalog::Cache::open(&cache.dir, cache.budget) else { return false; }; - let Ok(catalog) = Catalog::open(&cache.catalog_path) else { + if held + .as_ref() + .is_none_or(|(path, _)| *path != cache.catalog_path) + { + *held = Catalog::open(&cache.catalog_path) + .ok() + .map(|c| (cache.catalog_path.clone(), c)); + } + let Some((_, catalog)) = held.as_ref() else { return false; }; store.holds_original(catalog.connection(), cache.image)