Refactor and simplify code in index.rs, scan.rs, and database.rs

- Removed unnecessary references and improved clarity in `Indexer` method calls.
- Reorganized conditionals and eliminated redundant variable assignments in `scan.rs`.
- Simplified database initialization handling by removing unused commented-out code and improving formatting in `database.rs`.
This commit is contained in:
elipeter 2025-06-23 17:49:15 +02:00
parent 8bc16ac940
commit 952e83453a
3 changed files with 9 additions and 18 deletions

View file

@ -53,7 +53,7 @@ pub fn build_index(
let pool = Indexer::init(db_path)?;
{
let idx = Indexer::from_pool(&project_name, &pool).unwrap();
let idx = Indexer::from_pool(project_name, &pool).unwrap();
idx.clear()?;
}
@ -83,7 +83,7 @@ pub fn build_index(
}).unwrap();
{
let idx = Indexer::from_pool(&project_name, &pool)?;
let idx = Indexer::from_pool(project_name, &pool)?;
idx.vacuum()?;
}

View file

@ -35,10 +35,9 @@ pub fn handle(
) -> Result<(), Box<dyn std::error::Error>> {
let scan_path = Path::new(path).canonicalize()?;
let (project_name, db_path) = get_project_info(&scan_path, database_dir)?;
let diags: Vec<Diag>;
if no_index {
diags = scan_filesystem(&scan_path, config).unwrap();
let diags: Vec<Diag> = if no_index {
scan_filesystem(&scan_path, config).unwrap()
} else {
if rebuild_index || !db_path.exists() {
tracing::debug!("Scanning filesystem index filesystem");
@ -46,12 +45,12 @@ pub fn handle(
}
let pool = Indexer::init(&db_path)?;
diags = scan_with_index_parallel(&project_name, pool, config)?;
}
scan_with_index_parallel(&project_name, pool, config)?
};
tracing::debug!("Found {:?} issues.", diags.len());
if format == "console" || (format == "" && config.output.default_format == "console") {
if format == "console" || (format.is_empty() && config.output.default_format == "console") {
tracing::debug!("Printing to console");
for d in &diags {
let sev_str = match d.severity {

View file

@ -59,12 +59,12 @@ pub mod index {
let flags = OpenFlags::SQLITE_OPEN_READ_WRITE
| OpenFlags::SQLITE_OPEN_CREATE
| OpenFlags::SQLITE_OPEN_FULL_MUTEX;
let manager = SqliteConnectionManager::file(&database_path).with_flags(flags);
let manager = SqliteConnectionManager::file(database_path).with_flags(flags);
let pool = Arc::new(Pool::new(manager)?);
{
let conn = pool.get()?;
conn.pragma_update(None, "journal_mode", &"WAL")?;
conn.pragma_update(None, "journal_mode", "WAL")?;
conn.execute_batch(SCHEMA)?;
}
Ok(pool)
@ -81,14 +81,6 @@ pub mod index {
// helper so code below can treat PooledConnection like &Connection
fn c(&self) -> &Connection { self.conn.deref() }
/// Open (or create) the DB at `database_path` for the given project name.
// pub fn new(project: &str, database_path: &Path) -> Result<Self, Box<dyn std::error::Error>> {
// let conn = Connection::open(database_path)?;
// conn.pragma_update(None, "journal_mode", &"WAL")?;
// conn.execute_batch(SCHEMA)?;
// Ok(Self { conn, project: project.to_owned() })
// }
/// Return true when the file *content* or *mtime* changed since the last scan.
pub fn should_scan(&self, path: &Path) -> Result<bool, Box<dyn std::error::Error>> {
let meta = fs::metadata(path)?;