Skip to content

Commit 96cbd80

Browse files
committed
fix: resolve Rust 1.95 clippy lints (collapsible_match, sort_by_key, while_let, checked_div)
1 parent e8fe4bc commit 96cbd80

14 files changed

Lines changed: 64 additions & 82 deletions

File tree

nodedb-sql/src/planner/dml.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -548,12 +548,10 @@ fn collect_pk_equalities(expr: &ast::Expr, pk: &str, keys: &mut Vec<SqlValue>) {
548548
expr: inner,
549549
list,
550550
negated: false,
551-
} => {
552-
if is_column(inner, pk) {
553-
for item in list {
554-
if let Ok(v) = expr_to_sql_value(item) {
555-
keys.push(v);
556-
}
551+
} if is_column(inner, pk) => {
552+
for item in list {
553+
if let Ok(v) = expr_to_sql_value(item) {
554+
keys.push(v);
557555
}
558556
}
559557
}

nodedb-sql/src/planner/select.rs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -572,25 +572,24 @@ fn try_extract_sort_search(
572572
},
573573
}));
574574
}
575-
SearchTrigger::TextSearch => {
576-
if args.len() >= 2 {
577-
let query_text = extract_string_literal(&args[1])?;
578-
let limit = match plan {
579-
SqlPlan::Scan { limit, .. } => limit.unwrap_or(10),
580-
_ => 10,
581-
};
582-
return Ok(Some(SqlPlan::TextSearch {
583-
collection,
584-
query: query_text,
585-
top_k: limit,
586-
fuzzy: true,
587-
filters: match plan {
588-
SqlPlan::Scan { filters, .. } => filters.clone(),
589-
_ => Vec::new(),
590-
},
591-
}));
592-
}
575+
SearchTrigger::TextSearch if args.len() >= 2 => {
576+
let query_text = extract_string_literal(&args[1])?;
577+
let limit = match plan {
578+
SqlPlan::Scan { limit, .. } => limit.unwrap_or(10),
579+
_ => 10,
580+
};
581+
return Ok(Some(SqlPlan::TextSearch {
582+
collection,
583+
query: query_text,
584+
top_k: limit,
585+
fuzzy: true,
586+
filters: match plan {
587+
SqlPlan::Scan { filters, .. } => filters.clone(),
588+
_ => Vec::new(),
589+
},
590+
}));
593591
}
592+
SearchTrigger::TextSearch => {}
594593
SearchTrigger::HybridSearch => {
595594
return plan_hybrid_from_sort(&args, &collection, plan, functions);
596595
}

nodedb/src/control/planner/procedural/executor/core/dispatch.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,7 @@ fn fold_literal_string_concat(sql: &str) -> String {
196196
};
197197

198198
let mut folded = false;
199-
loop {
200-
let Some(op_end) = consume_string_concat_operator(bytes, cursor) else {
201-
break;
202-
};
199+
while let Some(op_end) = consume_string_concat_operator(bytes, cursor) {
203200
let next_lit = skip_ascii_whitespace(bytes, op_end);
204201
let Some((next_cursor, next_literal)) = parse_single_quoted_literal(sql, next_lit)
205202
else {

nodedb/src/control/planner/sql_plan_convert/value/time_range.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ fn extract_time_bounds_from_filter(expr: &FilterExpr, min_ts: &mut i64, max_ts:
2323
FilterExpr::Comparison { field, op, value } if is_time_field(field) => {
2424
if let Some(ms) = sql_value_to_timestamp_ms(value) {
2525
match op {
26-
nodedb_sql::types::CompareOp::Ge | nodedb_sql::types::CompareOp::Gt => {
27-
if ms > *min_ts {
28-
*min_ts = ms;
29-
}
26+
nodedb_sql::types::CompareOp::Ge | nodedb_sql::types::CompareOp::Gt
27+
if ms > *min_ts =>
28+
{
29+
*min_ts = ms;
3030
}
31-
nodedb_sql::types::CompareOp::Le | nodedb_sql::types::CompareOp::Lt => {
32-
if ms < *max_ts {
33-
*max_ts = ms;
34-
}
31+
nodedb_sql::types::CompareOp::Le | nodedb_sql::types::CompareOp::Lt
32+
if ms < *max_ts =>
33+
{
34+
*max_ts = ms;
3535
}
3636
nodedb_sql::types::CompareOp::Eq => {
3737
*min_ts = ms;

nodedb/src/control/security/catalog/checkpoints.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ impl SystemCatalog {
110110
}
111111

112112
// Sort by created_at descending (most recent first).
113-
records.sort_by(|a, b| b.created_at.cmp(&a.created_at));
113+
records.sort_by_key(|r| std::cmp::Reverse(r.created_at));
114114

115115
if records.len() > limit && limit > 0 {
116116
records.truncate(limit);

nodedb/src/control/security/explain.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,12 @@ pub fn lint_predicate(predicate: &super::predicate::RlsPredicate) -> Vec<String>
166166
super::predicate::RlsPredicate::AlwaysFalse => {
167167
warnings.push("contradiction: predicate is always false (blocks everything)".into());
168168
}
169-
super::predicate::RlsPredicate::Compare { value, .. } => {
170-
if !value.is_auth_ref() && matches!(value, super::predicate::PredicateValue::Literal(_))
171-
{
172-
warnings.push(
173-
"static predicate: no $auth reference — same result for all users".into(),
174-
);
175-
}
169+
super::predicate::RlsPredicate::Compare { value, .. }
170+
if !value.is_auth_ref()
171+
&& matches!(value, super::predicate::PredicateValue::Literal(_)) =>
172+
{
173+
warnings
174+
.push("static predicate: no $auth reference — same result for all users".into());
176175
}
177176
super::predicate::RlsPredicate::And(children)
178177
| super::predicate::RlsPredicate::Or(children) => {

nodedb/src/control/server/native/session.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -418,17 +418,12 @@ fn chunk_large_response(
418418
};
419419
let sample_bytes = codec::encode_response(&sample_resp, format)?;
420420
let sample_count = total_rows.min(100);
421-
let per_row_estimate = if sample_count > 0 {
422-
sample_bytes.len() / sample_count
423-
} else {
424-
256 // fallback
425-
};
421+
let per_row_estimate = sample_bytes.len().checked_div(sample_count).unwrap_or(256);
426422

427-
let rows_per_chunk = if per_row_estimate > 0 {
428-
(target_size / per_row_estimate).max(1)
429-
} else {
430-
1000
431-
};
423+
let rows_per_chunk = target_size
424+
.checked_div(per_row_estimate)
425+
.map(|v| v.max(1))
426+
.unwrap_or(1000);
432427

433428
let mut frames = Vec::new();
434429
let chunks: Vec<_> = rows.chunks(rows_per_chunk).collect();

nodedb/src/control/server/resp/handler.rs

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -259,27 +259,23 @@ async fn handle_scan(cmd: &RespCommand, session: &RespSession, state: &SharedSta
259259
i += 2;
260260
}
261261
// NodeDB extension: SCAN 0 FILTER <field> = <value>
262-
Some(ref flag) if flag == "FILTER" => {
262+
Some(ref flag) if flag == "FILTER" && i + 4 <= cmd.argc() => {
263263
// Parse simple "field = value" predicate (needs 4 args: FILTER field = value).
264-
if i + 4 <= cmd.argc() {
265-
let field = cmd.arg_str(i + 1).unwrap_or("");
266-
let _op = cmd.arg_str(i + 2).unwrap_or(""); // "=" expected
267-
let value = cmd.arg_str(i + 3).unwrap_or("");
268-
let scan_filter = serde_json::json!([{
269-
"field": field,
270-
"op": "eq",
271-
"value": value,
272-
}]);
273-
match nodedb_types::json_to_msgpack(&scan_filter) {
274-
Ok(bytes) => filter_bytes = bytes,
275-
Err(_) => {
276-
return RespValue::err("ERR filter serialization failed");
277-
}
264+
let field = cmd.arg_str(i + 1).unwrap_or("");
265+
let _op = cmd.arg_str(i + 2).unwrap_or(""); // "=" expected
266+
let value = cmd.arg_str(i + 3).unwrap_or("");
267+
let scan_filter = serde_json::json!([{
268+
"field": field,
269+
"op": "eq",
270+
"value": value,
271+
}]);
272+
match nodedb_types::json_to_msgpack(&scan_filter) {
273+
Ok(bytes) => filter_bytes = bytes,
274+
Err(_) => {
275+
return RespValue::err("ERR filter serialization failed");
278276
}
279-
i += 4;
280-
} else {
281-
i += 1;
282277
}
278+
i += 4;
283279
}
284280
_ => {
285281
i += 1;

nodedb/src/control/server/sync/listener.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,9 +316,9 @@ async fn handle_sync_session(
316316
}
317317
}
318318
Ok(Message::Ping(data)) => {
319-
if ws.send(Message::Pong(data)).await.is_err() {
319+
let Ok(_) = ws.send(Message::Pong(data)).await else {
320320
break;
321-
}
321+
};
322322
}
323323
Ok(Message::Close(_)) => break,
324324
Err(e) => {

nodedb/src/data/executor/handlers/document/text_extract.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@ pub fn extract_indexable_text(doc: &serde_json::Value) -> String {
1414

1515
pub(super) fn collect_text(val: &serde_json::Value, parts: &mut Vec<String>) {
1616
match val {
17-
serde_json::Value::String(s) => {
18-
if !s.is_empty() {
19-
parts.push(s.clone());
20-
}
17+
serde_json::Value::String(s) if !s.is_empty() => {
18+
parts.push(s.clone());
2119
}
2220
serde_json::Value::Object(map) => {
2321
for v in map.values() {

0 commit comments

Comments
 (0)