fix: address P1 and P2 review issues from PR #8 round 7

indexer: clear duplicate scan cache (folder + global) at the end of
every do_index so stale groups are never presented after a reindex;
previously a file modified or replaced on disk would still appear as a
duplicate candidate from the cached result until a manual rescan

db/vector: replace timestamp-based HNSW revision with a monotonically
incremented integer counter (app_kv.embedding_revision); mark_embedding_ready
atomically increments the counter so two embeddings saved within the same
second correctly advance the revision; get_embedding_revision now reads
this counter instead of MAX(embedding_updated_at), preventing the HNSW
cache from serving stale vectors after same-second batch updates
This commit is contained in:
2026-06-07 22:30:02 +01:00
parent 7efb187971
commit 20c43d2056
3 changed files with 30 additions and 7 deletions
+11 -7
View File
@@ -215,13 +215,17 @@ pub fn get_image_embedding(conn: &Connection, image_id: i64) -> Result<Option<Ve
}
pub fn get_embedding_revision(conn: &Connection) -> Result<String> {
let count: i64 = conn.query_row("SELECT COUNT(*) FROM image_vec", [], |row| row.get(0))?;
let max_updated_at: Option<String> = conn.query_row(
"SELECT MAX(embedding_updated_at) FROM images WHERE embedding_status = 'ready'",
[],
|row| row.get(0),
)?;
Ok(format!("{}:{}", count, max_updated_at.unwrap_or_default()))
// Use the monotonically incremented app_kv counter so that two embeddings
// saved within the same clock second still advance the revision, preventing
// the HNSW cache from serving stale vectors.
let revision: i64 = conn
.query_row(
"SELECT COALESCE((SELECT value FROM app_kv WHERE key = 'embedding_revision'), 0)",
[],
|row| row.get(0),
)
.unwrap_or(0);
Ok(revision.to_string())
}
// fn image_ids_for_folder(