Skip to content

Commit c331143

Browse files
committed
Drive indexing: fix DB transaction issue
- Was a bug in the implementation we just submitted, caused excessive logging
1 parent 7d751d5 commit c331143

3 files changed

Lines changed: 17 additions & 12 deletions

File tree

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1207,10 +1207,14 @@ async fn run_background_verification(
12071207
// parent and reconcile with DB.
12081208
let verify_result = verify_affected_dirs(&affected_paths, &writer);
12091209

1210-
// Scan newly discovered directories (inserts children + computes subtree aggregates)
1210+
// Scan newly discovered directories (inserts children + computes subtree aggregates).
1211+
// Skip excluded paths (system dirs like /System, /dev) that aren't in the index.
12111212
if !verify_result.new_dir_paths.is_empty() {
12121213
let cancelled = AtomicBool::new(false);
12131214
for dir_path in &verify_result.new_dir_paths {
1215+
if scanner::should_exclude(dir_path) {
1216+
continue;
1217+
}
12141218
match scanner::scan_subtree(Path::new(dir_path), &writer, &cancelled) {
12151219
Ok(summary) => {
12161220
log::debug!(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ fn build_walker(root: &Path, num_threads: usize, is_volume_root: bool) -> WalkDi
410410
// ── Helpers ──────────────────────────────────────────────────────────
411411

412412
/// Check if a path should be excluded from scanning.
413-
fn should_exclude(path_str: &str) -> bool {
413+
pub(super) fn should_exclude(path_str: &str) -> bool {
414414
// Check explicit exclusion prefixes
415415
for prefix in EXCLUDED_PREFIXES {
416416
if path_str.starts_with(prefix) {

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -428,8 +428,12 @@ fn process_message(conn: &rusqlite::Connection, msg: WriteMessage, stats: &Write
428428
/// Starts at `start_id` (typically the parent of the affected entry) and
429429
/// walks up to the root sentinel. Each ancestor gets its dir_stats updated
430430
/// with the given delta. Creates dir_stats rows if they don't exist.
431+
///
432+
/// Uses direct SQL statements (no transaction) because this function is
433+
/// always called from within the writer thread, which may already be inside
434+
/// a `BEGIN IMMEDIATE` transaction (for example, during replay).
431435
fn propagate_delta_by_id(conn: &rusqlite::Connection, start_id: i64, size_delta: i64, file_delta: i32, dir_delta: i32) {
432-
use crate::indexing::store::{DirStatsById, ROOT_ID};
436+
use crate::indexing::store::ROOT_ID;
433437

434438
let mut current_id = start_id;
435439
while current_id != 0 {
@@ -449,16 +453,13 @@ fn propagate_delta_by_id(conn: &rusqlite::Connection, start_id: i64, size_delta:
449453
),
450454
};
451455

452-
if let Err(e) = IndexStore::upsert_dir_stats_by_id(
453-
conn,
454-
&[DirStatsById {
455-
entry_id: current_id,
456-
recursive_size: new_size,
457-
recursive_file_count: new_files,
458-
recursive_dir_count: new_dirs,
459-
}],
456+
if let Err(e) = conn.execute(
457+
"INSERT OR REPLACE INTO dir_stats
458+
(entry_id, recursive_size, recursive_file_count, recursive_dir_count)
459+
VALUES (?1, ?2, ?3, ?4)",
460+
rusqlite::params![current_id, new_size, new_files, new_dirs],
460461
) {
461-
log::warn!("propagate_delta_by_id: upsert_dir_stats_by_id failed for id={current_id}: {e}");
462+
log::warn!("propagate_delta_by_id: upsert failed for id={current_id}: {e}");
462463
break;
463464
}
464465

0 commit comments

Comments
 (0)