Fetch the repairs first, or they never happen

The repair added in 051447b was appended to the work list:

    wanted.extend(repair);

Behind every un-indexed image in the library. On this library that is position
23,000-odd — roughly two hours of fetching before the first repair is reached,
which inside one session is indistinguishable from the feature not existing.
The log said it had found them and the screen stayed empty, which is the worst
combination of the two.

They go first now. There are a few hundred of them against tens of thousands of
un-indexed images, and they are precisely the images the People screen is
failing to draw at this moment — so the ordering costs nothing and is the
difference between the grid filling in within a minute and not filling in at
all.

A failure to build the un-indexed half no longer discards the repairs either:
the pass runs with whatever it has rather than returning empty.

Verified on the live catalog: 455 images hold faces, 251 already have a proxy
from the fixed sweep, and the remaining 204 are what now sits at the front of
the queue. The stored proxies check out — a valid JPEG at the large class,
49 KB — so the storing half of 051447b was already working.

471 tests pass, including one that the orphan is ordered ahead of the library.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-08-27 19:58:32 +02:00
co-authored by Claude Opus 5
parent 051447bda6
commit 371038614f
2 changed files with 89 additions and 22 deletions
+81 -14
View File
@@ -2848,26 +2848,39 @@ pub fn spawn_face_sweep(
}
};
let mut wanted = match faces_unindexed(&catalog, &model_id) {
Ok(w) => w,
// **Repairs first, and the order is the whole point.** These are the
// images the People screen is drawing *right now* and failing to, and
// there are a few hundred of them against tens of thousands of
// un-indexed ones. Appended instead, they sit two hours of fetching
// down the queue and the screen stays empty for the whole session —
// which is indistinguishable from the repair not existing.
let mut wanted = match faces_without_proxy(&catalog, &store, &model_id) {
Ok(repair) => {
if !repair.is_empty() {
log::info!(
"face sweep: repairing {} image(s) whose faces have no proxy to crop from",
repair.len()
);
}
repair
}
Err(e) => {
log::warn!("face sweep: {e}");
finish_empty(&tx);
return;
log::warn!("face sweep: looking for orphaned faces: {e}");
Vec::new()
}
};
// Disjoint from the above by construction: an image with faces recorded
// is not an image with no `face_index` row.
match faces_without_proxy(&catalog, &store, &model_id) {
Ok(repair) if !repair.is_empty() => {
log::info!(
"face sweep: {} image(s) have faces with no proxy to crop from",
repair.len()
);
wanted.extend(repair);
match faces_unindexed(&catalog, &model_id) {
Ok(fresh) => wanted.extend(fresh),
Err(e) => {
log::warn!("face sweep: {e}");
if wanted.is_empty() {
finish_empty(&tx);
return;
}
}
Ok(_) => {}
Err(e) => log::warn!("face sweep: looking for orphaned faces: {e}"),
}
let total = wanted.len();
@@ -4594,6 +4607,60 @@ mod tests {
let _ = std::fs::remove_dir_all(&store_dir);
}
/// Ordering is load-bearing. A repair queued behind every un-indexed image
/// in the library is a repair that does not happen inside a session, and
/// the screen it was meant to fix stays empty.
#[test]
fn repairs_are_reached_before_the_rest_of_the_library() {
let catalog = with_images(50);
let ids = image_ids(&catalog);
let store_dir = std::env::temp_dir().join(format!(
"dr-face-order-test-{}-{:?}",
std::process::id(),
std::thread::current().id()
));
let _ = std::fs::remove_dir_all(&store_dir);
std::fs::create_dir_all(&store_dir).unwrap();
let store = ThumbStore::open(&store_dir).unwrap();
// One image late in the library has a face and no proxy.
let face = dr_catalog::faces::DetectedFace {
x: 0.1,
y: 0.1,
w: 0.2,
h: 0.2,
landmarks: [(0.0, 0.0); 5],
confidence: 0.9,
embedding: vec![0u8; 1024],
crop_px: 120.0,
model_id: "w600k_mbf".into(),
};
let orphan = ids[40];
dr_catalog::faces::record_detections(
catalog.connection(),
orphan,
"w600k_mbf",
1024,
std::slice::from_ref(&face),
)
.unwrap();
let mut wanted = faces_without_proxy(&catalog, &store, "w600k_mbf").unwrap();
wanted.extend(faces_unindexed(&catalog, "w600k_mbf").unwrap());
assert_eq!(
wanted.first().map(|r| r.image_id),
Some(orphan.0 as i64),
"the image the screen cannot draw must be fetched first"
);
assert_eq!(
wanted.len(),
50,
"49 un-indexed plus the one being repaired"
);
let _ = std::fs::remove_dir_all(&store_dir);
}
/// The regression this whole pass exists for.
///
/// The previous work list intersected with the thumbnail store, so a