chore: clippy fixes

This commit is contained in:
Per Stark
2025-10-16 20:29:15 +02:00
parent 7332347f1a
commit 44e5d8a2fc
10 changed files with 49 additions and 34 deletions

View File

@@ -60,3 +60,14 @@ state-machines = "0.2.0"
[profile.dist] [profile.dist]
inherits = "release" inherits = "release"
lto = "thin" lto = "thin"
[workspace.lints.clippy]
perf = { level = "warn", priority = -1 }
pedantic = { level = "warn", priority = -1 }
nursery = { level = "warn", priority = -1 }
cargo = { level = "warn", priority = -1 }
needless_question_mark = "allow"
single_call_fn = "allow"
must_use_candidate = "allow"

View File

@@ -4,6 +4,9 @@ version = "0.1.0"
edition = "2021" edition = "2021"
license = "AGPL-3.0-or-later" license = "AGPL-3.0-or-later"
[lints]
workspace = true
[dependencies] [dependencies]
tokio = { workspace = true } tokio = { workspace = true }
serde = { workspace = true } serde = { workspace = true }

View File

@@ -4,6 +4,9 @@ version = "0.1.0"
edition = "2021" edition = "2021"
license = "AGPL-3.0-or-later" license = "AGPL-3.0-or-later"
[lints]
workspace = true
[dependencies] [dependencies]
# Workspace dependencies # Workspace dependencies
tokio = { workspace = true } tokio = { workspace = true }

View File

@@ -4,6 +4,9 @@ version = "0.1.0"
edition = "2021" edition = "2021"
license = "AGPL-3.0-or-later" license = "AGPL-3.0-or-later"
[lints]
workspace = true
[dependencies] [dependencies]
tokio = { workspace = true } tokio = { workspace = true }
serde = { workspace = true } serde = { workspace = true }

View File

@@ -4,6 +4,9 @@ version = "0.1.0"
edition = "2021" edition = "2021"
license = "AGPL-3.0-or-later" license = "AGPL-3.0-or-later"
[lints]
workspace = true
[dependencies] [dependencies]
tokio = { workspace = true } tokio = { workspace = true }
serde = { workspace = true } serde = { workspace = true }

View File

@@ -150,13 +150,8 @@ pub async fn get_task_updates_stream(
let db = state.db.clone(); let db = state.db.clone();
// 1. Check for authenticated user // 1. Check for authenticated user
let current_user = match auth.current_user { let Some(current_user) = auth.current_user else {
Some(user) => user, return Sse::new(create_error_stream("User not authenticated"));
None => {
return Sse::new(create_error_stream(
"User not authenticated. Please log in.",
));
}
}; };
// 2. Fetch task for initial authorization and to ensure it exists // 2. Fetch task for initial authorization and to ensure it exists
@@ -236,10 +231,10 @@ pub async fn get_task_updates_stream(
Err(db_err) => { Err(db_err) => {
error!("Database error while fetching task '{}': {:?}", task_id, db_err); error!("Database error while fetching task '{}': {:?}", task_id, db_err);
consecutive_db_errors += 1; consecutive_db_errors += 1;
yield Ok(Event::default().event("error").data(format!("Temporary error fetching task update (attempt {}).", consecutive_db_errors))); yield Ok(Event::default().event("error").data(format!("Temporary error fetching task update (attempt {consecutive_db_errors}).")));
if consecutive_db_errors >= max_consecutive_db_errors { if consecutive_db_errors >= max_consecutive_db_errors {
error!("Max consecutive DB errors reached for task '{}'. Closing stream.", task_id); error!("Max consecutive DB errors reached for task '{task_id}'. Closing stream.");
yield Ok(Event::default().event("error").data("Persistent error fetching task updates. Stream closed.")); yield Ok(Event::default().event("error").data("Persistent error fetching task updates. Stream closed."));
yield Ok(Event::default().event("close_stream").data("Stream complete")); yield Ok(Event::default().event("close_stream").data("Stream complete"));
break; break;
@@ -257,14 +252,10 @@ pub async fn get_task_updates_stream(
) )
} }
Ok(None) => Sse::new(create_error_stream(format!( Ok(None) => Sse::new(create_error_stream(format!(
"Task with ID '{}' not found.", "Task with ID '{task_id}' not found."
task_id
))), ))),
Err(e) => { Err(e) => {
error!( error!("Failed to fetch task '{task_id}' for authorization: {e:?}");
"Failed to fetch task '{}' for authorization: {:?}",
task_id, e
);
Sse::new(create_error_stream( Sse::new(create_error_stream(
"An error occurred while retrieving task details. Please try again later.", "An error occurred while retrieving task details. Please try again later.",
)) ))

View File

@@ -90,10 +90,8 @@ pub async fn create_knowledge_entity(
let description = form.description.trim().to_string(); let description = form.description.trim().to_string();
let entity_type = KnowledgeEntityType::from(form.entity_type.trim().to_string()); let entity_type = KnowledgeEntityType::from(form.entity_type.trim().to_string());
let embedding_input = format!( let embedding_input =
"name: {}, description: {}, type: {:?}", format!("name: {name}, description: {description}, type: {entity_type:?}");
name, description, entity_type
);
let embedding = generate_embedding(&state.openai_client, &embedding_input, &state.db).await?; let embedding = generate_embedding(&state.openai_client, &embedding_input, &state.db).await?;
let source_id = format!("manual::{}", Uuid::new_v4()); let source_id = format!("manual::{}", Uuid::new_v4());
@@ -126,7 +124,7 @@ pub async fn create_knowledge_entity(
.collect(); .collect();
let mut unique_ids: HashSet<String> = HashSet::new(); let mut unique_ids: HashSet<String> = HashSet::new();
for target_id in form.relationship_ids.into_iter() { for target_id in form.relationship_ids {
if target_id == new_entity.id { if target_id == new_entity.id {
continue; continue;
} }
@@ -333,7 +331,7 @@ async fn build_knowledge_base_data(
if encoded.is_empty() { if encoded.is_empty() {
String::new() String::new()
} else { } else {
format!("&{}", encoded) format!("&{encoded}")
} }
}; };
@@ -662,7 +660,7 @@ pub async fn get_knowledge_graph_json(
let mut degree_count: HashMap<String, usize> = HashMap::new(); let mut degree_count: HashMap<String, usize> = HashMap::new();
let mut links: Vec<GraphLink> = Vec::new(); let mut links: Vec<GraphLink> = Vec::new();
for rel in relationships.iter() { for rel in &relationships {
if entity_ids.contains(&rel.in_) && entity_ids.contains(&rel.out) { if entity_ids.contains(&rel.in_) && entity_ids.contains(&rel.out) {
// undirected counting for degree // undirected counting for degree
*degree_count.entry(rel.in_.clone()).or_insert(0) += 1; *degree_count.entry(rel.in_.clone()).or_insert(0) += 1;
@@ -689,17 +687,14 @@ pub async fn get_knowledge_graph_json(
} }
// Normalize filter parameters: convert empty strings or "none" (case-insensitive) to None // Normalize filter parameters: convert empty strings or "none" (case-insensitive) to None
fn normalize_filter(input: Option<String>) -> Option<String> { fn normalize_filter(input: Option<String>) -> Option<String> {
match input { input.and_then(|s| {
None => None, let trimmed = s.trim();
Some(s) => { if trimmed.is_empty() || trimmed.eq_ignore_ascii_case("none") {
let trimmed = s.trim(); None
if trimmed.is_empty() || trimmed.eq_ignore_ascii_case("none") { } else {
None Some(trim_matching_quotes(trimmed).to_string())
} else {
Some(trim_matching_quotes(trimmed).to_string())
}
} }
} })
} }
fn trim_matching_quotes(value: &str) -> &str { fn trim_matching_quotes(value: &str) -> &str {
@@ -739,8 +734,8 @@ pub async fn show_edit_knowledge_entity_form(
"knowledge/edit_knowledge_entity_modal.html", "knowledge/edit_knowledge_entity_modal.html",
EntityData { EntityData {
entity, entity,
user,
entity_types, entity_types,
user,
}, },
)) ))
} }

View File

@@ -16,7 +16,7 @@ pub struct Pagination {
} }
impl Pagination { impl Pagination {
pub fn new( pub const fn new(
current_page: usize, current_page: usize,
per_page: usize, per_page: usize,
total_items: usize, total_items: usize,

View File

@@ -4,6 +4,9 @@ version = "0.1.0"
edition = "2021" edition = "2021"
license = "AGPL-3.0-or-later" license = "AGPL-3.0-or-later"
[lints]
workspace = true
[dependencies] [dependencies]
tokio = { workspace = true } tokio = { workspace = true }
serde = { workspace = true } serde = { workspace = true }

View File

@@ -5,6 +5,9 @@ edition = "2021"
repository = "https://github.com/perstarkse/minne" repository = "https://github.com/perstarkse/minne"
license = "AGPL-3.0-or-later" license = "AGPL-3.0-or-later"
[lints]
workspace = true
[dependencies] [dependencies]
tokio = { workspace = true } tokio = { workspace = true }
serde = { workspace = true } serde = { workspace = true }