Skip to content

Commit 8aeabf9

Browse files
AlexMikhalevTerraphim CI
andauthored
fix(usage-cli-commands): resolve clippy warnings for CI (#753)
- Fix LegacyTerm missing #[derive(Deserialize)] in terraphim_automata - Remove clone_on_copy for u64 IDs in builder.rs, rolegraph, cli, mcp_server - Replace map_or with is_some_and in rolegraph/medical.rs - Suppress dead_code warnings on deserialization-only structs in terraphim_usage - Remove unused imports from terraphim_usage providers - Replace redundant closures with variant constructors in store.rs - Remove unnecessary i64-to-i64 cast in ExecutionRecord::duration_ms Refs #229 Co-authored-by: Terraphim CI <alex@terraphim.ai>
1 parent 56d1ecf commit 8aeabf9

14 files changed

Lines changed: 1215 additions & 302 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/terraphim_automata/src/builder.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,8 @@ fn index_inner(name: String, messages: Vec<Message>) -> Thesaurus {
159159
let concept_with_display = match current_concept {
160160
Some(ref cwd) => {
161161
// Create NormalizedTerm with display_value preserving original case
162-
let nterm =
163-
NormalizedTerm::new(cwd.concept.id.clone(), cwd.concept.value.clone())
164-
.with_display_value(cwd.display_name.clone());
162+
let nterm = NormalizedTerm::new(cwd.concept.id, cwd.concept.value.clone())
163+
.with_display_value(cwd.display_name.clone());
165164
thesaurus.insert(cwd.concept.value.clone(), nterm.clone());
166165
cwd
167166
}
@@ -173,7 +172,7 @@ fn index_inner(name: String, messages: Vec<Message>) -> Thesaurus {
173172
for synonym in synonyms {
174173
// Synonyms also get the same display_value (the concept's original name)
175174
let nterm = NormalizedTerm::new(
176-
concept_with_display.concept.id.clone(),
175+
concept_with_display.concept.id,
177176
concept_with_display.concept.value.clone(),
178177
)
179178
.with_display_value(concept_with_display.display_name.clone());

crates/terraphim_automata/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,9 @@ fn parse_thesaurus_json(contents: &str) -> Result<Thesaurus> {
354354
}
355355

356356
#[derive(Deserialize)]
357+
#[allow(dead_code)]
357358
struct LegacyTerm {
359+
#[allow(dead_code)]
358360
id: u64,
359361
nterm: String,
360362
#[serde(default)]

crates/terraphim_cli/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ async fn handle_thesaurus(
711711
let thesaurus = service.get_thesaurus(&role_name).await?;
712712

713713
let mut entries: Vec<_> = thesaurus.into_iter().collect();
714-
entries.sort_by_key(|(_, term)| term.id.clone());
714+
entries.sort_by_key(|(_, term)| term.id);
715715

716716
let total_count = entries.len();
717717
let terms: Vec<ThesaurusTerm> = entries

crates/terraphim_mcp_server/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ impl McpService {
340340
candidates.push(AutocompleteResult {
341341
term: meta.original_term.clone(),
342342
normalized_term: meta.normalized_term.clone(),
343-
id: meta.id.clone(),
343+
id: meta.id,
344344
url: meta.url.clone(),
345345
score: 0.0,
346346
});

crates/terraphim_rolegraph/src/lib.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ impl TriggerIndex {
114114
for token in &unique {
115115
*doc_freq.entry(token.to_string()).or_insert(0) += 1;
116116
}
117-
self.triggers.insert(node_id.clone(), tokens);
117+
self.triggers.insert(*node_id, tokens);
118118
}
119119

120120
// Compute IDF: log((N + 1) / (df + 1)) + 1 (smoothed)
@@ -175,7 +175,7 @@ impl TriggerIndex {
175175
let similarity = dot / (query_norm * doc_norm);
176176

177177
if similarity >= self.threshold {
178-
results.push((node_id.clone(), similarity));
178+
results.push((*node_id, similarity));
179179
}
180180
}
181181

@@ -242,7 +242,7 @@ impl TriggerIndex {
242242
pub fn get_trigger_descriptions(&self) -> AHashMap<u64, String> {
243243
self.triggers
244244
.iter()
245-
.map(|(node_id, tokens)| (node_id.clone(), tokens.join(" ")))
245+
.map(|(node_id, tokens)| (*node_id, tokens.join(" ")))
246246
.collect()
247247
}
248248
}
@@ -434,7 +434,7 @@ impl RoleGraph {
434434
log::trace!("Finding matching node IDs for text: '{text}'");
435435
self.ac
436436
.find_iter(text)
437-
.map(|mat| self.aho_corasick_values[mat.pattern()].clone())
437+
.map(|mat| self.aho_corasick_values[mat.pattern()])
438438
.collect()
439439
}
440440

@@ -669,7 +669,7 @@ impl RoleGraph {
669669
matched_edges: vec![edge.clone()],
670670
rank: total_rank,
671671
tags: vec![normalized_term.to_string()],
672-
nodes: vec![node_id.clone()],
672+
nodes: vec![node_id],
673673
quality_score: None,
674674
});
675675
}
@@ -678,7 +678,7 @@ impl RoleGraph {
678678
doc.rank += total_rank; // Adjust to correctly aggregate the rank
679679
doc.matched_edges.push(edge.clone());
680680
// Remove duplicate edges based on unique IDs
681-
doc.matched_edges.dedup_by_key(|e| e.id.clone());
681+
doc.matched_edges.dedup_by_key(|e| e.id);
682682
}
683683
}
684684
}
@@ -769,7 +769,7 @@ impl RoleGraph {
769769
matched_edges: vec![edge.clone()],
770770
rank: total_rank,
771771
tags: vec![normalized_term.to_string()],
772-
nodes: vec![node_id.clone()],
772+
nodes: vec![node_id],
773773
quality_score: None,
774774
});
775775
}
@@ -778,7 +778,7 @@ impl RoleGraph {
778778
doc.rank += total_rank; // Adjust to correctly aggregate the rank
779779
doc.matched_edges.push(edge.clone());
780780
// Remove duplicate edges based on unique IDs
781-
doc.matched_edges.dedup_by_key(|e| e.id.clone());
781+
doc.matched_edges.dedup_by_key(|e| e.id);
782782
}
783783
}
784784
}
@@ -873,21 +873,21 @@ impl RoleGraph {
873873
matched_edges: vec![edge.clone()],
874874
rank: total_rank,
875875
tags: vec![normalized_term.to_string()],
876-
nodes: vec![node_id.clone()],
876+
nodes: vec![node_id],
877877
quality_score: None,
878878
});
879879
}
880880
Entry::Occupied(mut e) => {
881881
let doc = e.get_mut();
882882
doc.rank += total_rank;
883883
doc.matched_edges.push(edge.clone());
884-
doc.matched_edges.dedup_by_key(|e| e.id.clone());
884+
doc.matched_edges.dedup_by_key(|e| e.id);
885885
// Add the tag if not already present
886886
if !doc.tags.contains(&normalized_term.to_string()) {
887887
doc.tags.push(normalized_term.to_string());
888888
}
889889
if !doc.nodes.contains(&node_id) {
890-
doc.nodes.push(node_id.clone());
890+
doc.nodes.push(node_id);
891891
}
892892
}
893893
}
@@ -977,7 +977,7 @@ impl RoleGraph {
977977
matched_edges: vec![edge.clone()],
978978
rank: total_rank,
979979
tags: vec![normalized_term.to_string()],
980-
nodes: vec![node_id.clone()],
980+
nodes: vec![node_id],
981981
quality_score: None,
982982
},
983983
vec![term.to_string()],
@@ -987,12 +987,12 @@ impl RoleGraph {
987987
let (doc, terms) = e.get_mut();
988988
doc.rank += total_rank;
989989
doc.matched_edges.push(edge.clone());
990-
doc.matched_edges.dedup_by_key(|e| e.id.clone());
990+
doc.matched_edges.dedup_by_key(|e| e.id);
991991
if !doc.tags.contains(&normalized_term.to_string()) {
992992
doc.tags.push(normalized_term.to_string());
993993
}
994994
if !doc.nodes.contains(&node_id) {
995-
doc.nodes.push(node_id.clone());
995+
doc.nodes.push(node_id);
996996
}
997997
if !terms.contains(&term.to_string()) {
998998
terms.push(term.to_string());
@@ -1026,7 +1026,7 @@ impl RoleGraph {
10261026
combined_doc
10271027
.matched_edges
10281028
.extend(term_doc.matched_edges.clone());
1029-
combined_doc.matched_edges.dedup_by_key(|e| e.id.clone());
1029+
combined_doc.matched_edges.dedup_by_key(|e| e.id);
10301030

10311031
for tag in &term_doc.tags {
10321032
if !combined_doc.tags.contains(tag) {
@@ -1036,7 +1036,7 @@ impl RoleGraph {
10361036

10371037
for node in &term_doc.nodes {
10381038
if !combined_doc.nodes.contains(node) {
1039-
combined_doc.nodes.push(node.clone());
1039+
combined_doc.nodes.push(*node);
10401040
}
10411041
}
10421042

crates/terraphim_rolegraph/src/medical.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,14 +260,14 @@ impl MedicalRoleGraph {
260260
for &condition_id in conditions {
261261
let is_contraindicated =
262262
// drug -> condition
263-
self.outgoing_edges.get(&drug_id).map_or(false, |edges| {
263+
self.outgoing_edges.get(&drug_id).is_some_and(|edges| {
264264
edges
265265
.iter()
266266
.any(|&(t, et)| t == condition_id && et == MedicalEdgeType::Contraindicates)
267267
})
268268
||
269269
// condition -> drug
270-
self.outgoing_edges.get(&condition_id).map_or(false, |edges| {
270+
self.outgoing_edges.get(&condition_id).is_some_and(|edges| {
271271
edges
272272
.iter()
273273
.any(|&(t, et)| t == drug_id && et == MedicalEdgeType::Contraindicates)

crates/terraphim_usage/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ which = "6.0"
2020
terraphim_persistence = { path = "../terraphim_persistence", optional = true }
2121
terraphim_types = { path = "../terraphim_types" }
2222
terraphim_settings = { path = "../terraphim_settings" }
23+
opendal = { version = "0.54", optional = true }
2324

2425
[features]
2526
default = ["persistence", "providers"]
26-
persistence = ["dep:terraphim_persistence"] # Enable storage via terraphim_persistence
27+
persistence = ["dep:terraphim_persistence", "dep:opendal"] # Enable storage via terraphim_persistence
2728
cli = ["dep:clap", "dep:colored", "dep:indicatif"] # Enable CLI commands
2829
providers = ["dep:reqwest"] # Enable external provider API fetchers

0 commit comments

Comments
 (0)