style: Apply cargo fmt and clippy fixes across codebase
Automated formatting and lint corrections from parallel agent work: - cargo fmt: import reordering (alphabetical), line wrapping to respect max width, trailing comma normalization, destructuring alignment, function signature reformatting, match arm formatting - clippy (pedantic): Range::contains() instead of manual comparisons, i64::from() instead of `as i64` casts, .clamp() instead of .max().min() chains, let-chain refactors (if-let with &&), #[allow(clippy::too_many_arguments)] and #[allow(clippy::field_reassign_with_default)] where warranted - Removed trailing blank lines and extra whitespace No behavioral changes. All existing tests pass unmodified. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -4,10 +4,10 @@ use console::style;
|
||||
use rusqlite::Connection;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::Config;
|
||||
use crate::core::db::create_connection;
|
||||
use crate::core::error::Result;
|
||||
use crate::core::paths::get_db_path;
|
||||
use crate::Config;
|
||||
|
||||
/// Result of the stats command.
|
||||
#[derive(Debug, Default, Serialize)]
|
||||
@@ -75,11 +75,7 @@ pub struct RepairResult {
|
||||
}
|
||||
|
||||
/// Run the stats command.
|
||||
pub fn run_stats(
|
||||
config: &Config,
|
||||
check: bool,
|
||||
repair: bool,
|
||||
) -> Result<StatsResult> {
|
||||
pub fn run_stats(config: &Config, check: bool, repair: bool) -> Result<StatsResult> {
|
||||
let db_path = get_db_path(config.storage.db_path.as_deref());
|
||||
let conn = create_connection(&db_path)?;
|
||||
|
||||
@@ -87,14 +83,22 @@ pub fn run_stats(
|
||||
|
||||
// Document counts
|
||||
result.documents.total = count_query(&conn, "SELECT COUNT(*) FROM documents")?;
|
||||
result.documents.issues =
|
||||
count_query(&conn, "SELECT COUNT(*) FROM documents WHERE source_type = 'issue'")?;
|
||||
result.documents.merge_requests =
|
||||
count_query(&conn, "SELECT COUNT(*) FROM documents WHERE source_type = 'merge_request'")?;
|
||||
result.documents.discussions =
|
||||
count_query(&conn, "SELECT COUNT(*) FROM documents WHERE source_type = 'discussion'")?;
|
||||
result.documents.truncated =
|
||||
count_query(&conn, "SELECT COUNT(*) FROM documents WHERE is_truncated = 1")?;
|
||||
result.documents.issues = count_query(
|
||||
&conn,
|
||||
"SELECT COUNT(*) FROM documents WHERE source_type = 'issue'",
|
||||
)?;
|
||||
result.documents.merge_requests = count_query(
|
||||
&conn,
|
||||
"SELECT COUNT(*) FROM documents WHERE source_type = 'merge_request'",
|
||||
)?;
|
||||
result.documents.discussions = count_query(
|
||||
&conn,
|
||||
"SELECT COUNT(*) FROM documents WHERE source_type = 'discussion'",
|
||||
)?;
|
||||
result.documents.truncated = count_query(
|
||||
&conn,
|
||||
"SELECT COUNT(*) FROM documents WHERE is_truncated = 1",
|
||||
)?;
|
||||
|
||||
// Embedding stats — skip gracefully if table doesn't exist (Gate A only)
|
||||
if table_exists(&conn, "embedding_metadata") {
|
||||
@@ -119,10 +123,14 @@ pub fn run_stats(
|
||||
result.fts.indexed = count_query(&conn, "SELECT COUNT(*) FROM documents_fts")?;
|
||||
|
||||
// Queue stats
|
||||
result.queues.dirty_sources =
|
||||
count_query(&conn, "SELECT COUNT(*) FROM dirty_sources WHERE last_error IS NULL")?;
|
||||
result.queues.dirty_sources_failed =
|
||||
count_query(&conn, "SELECT COUNT(*) FROM dirty_sources WHERE last_error IS NOT NULL")?;
|
||||
result.queues.dirty_sources = count_query(
|
||||
&conn,
|
||||
"SELECT COUNT(*) FROM dirty_sources WHERE last_error IS NULL",
|
||||
)?;
|
||||
result.queues.dirty_sources_failed = count_query(
|
||||
&conn,
|
||||
"SELECT COUNT(*) FROM dirty_sources WHERE last_error IS NOT NULL",
|
||||
)?;
|
||||
|
||||
if table_exists(&conn, "pending_discussion_fetches") {
|
||||
result.queues.pending_discussion_fetches = count_query(
|
||||
@@ -151,6 +159,7 @@ pub fn run_stats(
|
||||
}
|
||||
|
||||
// Integrity check
|
||||
#[allow(clippy::field_reassign_with_default)]
|
||||
if check {
|
||||
let mut integrity = IntegrityResult::default();
|
||||
|
||||
@@ -276,9 +285,7 @@ pub fn run_stats(
|
||||
}
|
||||
|
||||
fn count_query(conn: &Connection, sql: &str) -> Result<i64> {
|
||||
let count: i64 = conn
|
||||
.query_row(sql, [], |row| row.get(0))
|
||||
.unwrap_or(0);
|
||||
let count: i64 = conn.query_row(sql, [], |row| row.get(0)).unwrap_or(0);
|
||||
Ok(count)
|
||||
}
|
||||
|
||||
@@ -300,7 +307,10 @@ pub fn print_stats(result: &StatsResult) {
|
||||
println!(" Merge Requests: {}", result.documents.merge_requests);
|
||||
println!(" Discussions: {}", result.documents.discussions);
|
||||
if result.documents.truncated > 0 {
|
||||
println!(" Truncated: {}", style(result.documents.truncated).yellow());
|
||||
println!(
|
||||
" Truncated: {}",
|
||||
style(result.documents.truncated).yellow()
|
||||
);
|
||||
}
|
||||
println!();
|
||||
|
||||
@@ -318,13 +328,13 @@ pub fn print_stats(result: &StatsResult) {
|
||||
println!();
|
||||
|
||||
println!("{}", style("Queues").cyan().bold());
|
||||
println!(" Dirty sources: {} pending, {} failed",
|
||||
result.queues.dirty_sources,
|
||||
result.queues.dirty_sources_failed
|
||||
println!(
|
||||
" Dirty sources: {} pending, {} failed",
|
||||
result.queues.dirty_sources, result.queues.dirty_sources_failed
|
||||
);
|
||||
println!(" Discussion fetch: {} pending, {} failed",
|
||||
result.queues.pending_discussion_fetches,
|
||||
result.queues.pending_discussion_fetches_failed
|
||||
println!(
|
||||
" Discussion fetch: {} pending, {} failed",
|
||||
result.queues.pending_discussion_fetches, result.queues.pending_discussion_fetches_failed
|
||||
);
|
||||
if result.queues.pending_dependent_fetches > 0
|
||||
|| result.queues.pending_dependent_fetches_failed > 0
|
||||
@@ -431,10 +441,12 @@ pub fn print_stats_json(result: &StatsResult) {
|
||||
let output = StatsJsonOutput {
|
||||
ok: true,
|
||||
data: StatsResult {
|
||||
documents: DocumentStats { ..*&result.documents },
|
||||
embeddings: EmbeddingStats { ..*&result.embeddings },
|
||||
fts: FtsStats { ..*&result.fts },
|
||||
queues: QueueStats { ..*&result.queues },
|
||||
documents: DocumentStats { ..result.documents },
|
||||
embeddings: EmbeddingStats {
|
||||
..result.embeddings
|
||||
},
|
||||
fts: FtsStats { ..result.fts },
|
||||
queues: QueueStats { ..result.queues },
|
||||
integrity: result.integrity.as_ref().map(|i| IntegrityResult {
|
||||
ok: i.ok,
|
||||
fts_doc_mismatch: i.fts_doc_mismatch,
|
||||
|
||||
Reference in New Issue
Block a user