Skip to content

Commit 424eedb

Browse files
committed
Indexing: Fix lost scan metadata and stuck status
- Reset `expected_total_entries` to 0 after `ComputeAllAggregates` in the writer. Without this, micro-scan `InsertEntriesV2` batches emitted spurious `saving_entries` progress events that re-triggered the aggregation overlay permanently (no matching `index-aggregation-complete` followed). - Move `scan_completed_at` and other meta writes before the reconciler replay in `mod.rs`. The replay can fail (e.g. "database is locked") and cause an early return, which previously skipped persisting `scan_completed_at` — causing a full rescan on every subsequent startup.
1 parent 7551df2 commit 424eedb

File tree

2 files changed

+29
-23
lines changed

2 files changed

+29
-23
lines changed

apps/desktop/src-tauri/src/indexing/mod.rs

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,31 @@ impl IndexManager {
608608
},
609609
);
610610

611+
// Store scan metadata now, before the reconciler replay which
612+
// can fail (e.g. "database is locked") and cause an early return.
613+
// Without this, scan_completed_at is never persisted and the next
614+
// startup triggers a full rescan of the entire volume.
615+
let now = std::time::SystemTime::now()
616+
.duration_since(std::time::UNIX_EPOCH)
617+
.map(|d| d.as_secs().to_string())
618+
.unwrap_or_default();
619+
let _ = writer.send(WriteMessage::UpdateMeta {
620+
key: "scan_completed_at".to_string(),
621+
value: now,
622+
});
623+
let _ = writer.send(WriteMessage::UpdateMeta {
624+
key: "scan_duration_ms".to_string(),
625+
value: summary.duration_ms.to_string(),
626+
});
627+
let _ = writer.send(WriteMessage::UpdateMeta {
628+
key: "total_entries".to_string(),
629+
value: summary.total_entries.to_string(),
630+
});
631+
let _ = writer.send(WriteMessage::UpdateMeta {
632+
key: "volume_path".to_string(),
633+
value: "/".to_string(),
634+
});
635+
611636
// Open a read connection for path resolution during replay
612637
let replay_conn = match IndexStore::open_write_connection(&writer.db_path()) {
613638
Ok(c) => c,
@@ -665,28 +690,6 @@ impl IndexManager {
665690
*guard = Some(handle);
666691
}
667692

668-
// Store scan metadata via writer
669-
let now = std::time::SystemTime::now()
670-
.duration_since(std::time::UNIX_EPOCH)
671-
.map(|d| d.as_secs().to_string())
672-
.unwrap_or_default();
673-
let _ = writer.send(WriteMessage::UpdateMeta {
674-
key: "scan_completed_at".to_string(),
675-
value: now,
676-
});
677-
let _ = writer.send(WriteMessage::UpdateMeta {
678-
key: "scan_duration_ms".to_string(),
679-
value: summary.duration_ms.to_string(),
680-
});
681-
let _ = writer.send(WriteMessage::UpdateMeta {
682-
key: "total_entries".to_string(),
683-
value: summary.total_entries.to_string(),
684-
});
685-
let _ = writer.send(WriteMessage::UpdateMeta {
686-
key: "volume_path".to_string(),
687-
value: "/".to_string(),
688-
});
689-
690693
// Mark micro-scans as superseded (full scan data is authoritative)
691694
micro_scans.mark_full_scan_complete().await;
692695
}

apps/desktop/src-tauri/src/indexing/writer.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,8 +632,11 @@ fn process_message(
632632
&mut on_progress,
633633
)
634634
};
635-
// Maps are consumed; clear to free memory
635+
// Maps are consumed; clear to free memory.
636+
// Reset expected_total so micro-scan inserts don't emit
637+
// spurious saving_entries progress events after the full scan.
636638
accumulator.clear();
639+
expected_total_entries.store(0, Ordering::Relaxed);
637640
match result {
638641
Ok(count) => {
639642
log::info!(

0 commit comments

Comments
 (0)