Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 25 additions & 13 deletions codi-rs/src/symbol_index/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,23 +551,35 @@ impl Indexer {
let start = Instant::now();

let project_root = Path::new(&self.options.project_root);
let db_lock = db.lock().await;

// Get all indexed files from database
let indexed_files = db_lock.get_all_files()?;
// Get all indexed files from database (lock held briefly)
let indexed_files = {
let db_lock = db.lock().await;
db_lock.get_all_files()?
};

let mut deleted_count = 0u32;
// Collect paths to delete (no lock held during file I/O)
let paths_to_delete: Vec<String> = {
let mut to_delete = Vec::new();
for file_path in indexed_files {
let full_path = if file_path.starts_with('/') {
PathBuf::from(&file_path)
} else {
project_root.join(&file_path)
};

// Check which files no longer exist on disk
for file_path in indexed_files {
let full_path = if file_path.starts_with('/') {
PathBuf::from(&file_path)
} else {
project_root.join(&file_path)
};
if !full_path.exists() {
to_delete.push(file_path);
}
}
to_delete
};

if !full_path.exists() {
// Get file ID and delete
// Delete files from database (lock held briefly per operation)
let mut deleted_count = 0u32;
{
let db_lock = db.lock().await;
for file_path in paths_to_delete {
if let Ok(Some(file)) = db_lock.get_file(&file_path) {
db_lock.delete_file(file.id)?;
deleted_count += 1;
Expand Down