diff --git a/core/dr-catalog/examples/catalog_bench.rs b/core/dr-catalog/examples/catalog_bench.rs index f5227f7..3f94f21 100644 --- a/core/dr-catalog/examples/catalog_bench.rs +++ b/core/dr-catalog/examples/catalog_bench.rs @@ -155,8 +155,8 @@ fn local_original_count(conn: &rusqlite::Connection) -> i64 { conn.query_row( "SELECT count(*) FROM images i WHERE i.shadowed_by IS NULL AND i.trashed_at IS NULL - AND EXISTS (SELECT 1 FROM image_cache ic - WHERE ic.image_id = i.id AND ic.tier_actual >= 2)", + AND i.id IN (SELECT ic.image_id FROM image_cache ic + WHERE ic.tier_actual >= 2)", [], |r| r.get(0), ) diff --git a/ui/dr-ui/src/library/spans.rs b/ui/dr-ui/src/library/spans.rs index 08e70df..c6e2aac 100644 --- a/ui/dr-ui/src/library/spans.rs +++ b/ui/dr-ui/src/library/spans.rs @@ -364,13 +364,21 @@ pub(super) fn total_images_filtered( /// Whole-library, like the star counts beside it: the chip says what narrowing /// to it would show, so counting only the current window would make it /// describe the view it exists to change. +/// +/// Driven from `image_cache`, which holds a row only for what has been +/// fetched: an `IN` list the planner walks, probing `images` by id for each. +/// Spelled as a correlated `EXISTS` it walked every visible image and +/// probed the cache for each -- 19,000 probes to find 254 originals on the +/// reference library, 2 ms paid on every star keystroke beside the rating +/// counts. `image_id` is the cache's key, so the list holds each image once +/// and the count is the one the `EXISTS` gave. pub fn local_original_count(catalog: &Catalog) -> Result { let n: i64 = catalog.connection().query_row( &format!( "SELECT count(*) FROM images i WHERE {VISIBLE} - AND EXISTS (SELECT 1 FROM image_cache ic - WHERE ic.image_id = i.id AND ic.tier_actual >= {})", + AND i.id IN (SELECT ic.image_id FROM image_cache ic + WHERE ic.tier_actual >= {})", dr_types::Tier::Original.stored() ), [],