MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / handle_dbsize

Function handle_dbsize

nodedb/src/control/server/resp/handler.rs:398–426  ·  view source on GitHub ↗
(session: &RespSession, state: &SharedState)

Source from the content-addressed store, hash-verified

396// ---------------------------------------------------------------------------
397
398async fn handle_dbsize(session: &RespSession, state: &SharedState) -> RespValue {
399 let plan = PhysicalPlan::Kv(KvOp::Scan {
400 collection: session.collection.clone(),
401 cursor: Vec::new(),
402 count: 0,
403 filters: Vec::new(),
404 match_pattern: None,
405 sort_keys: Vec::new(),
406 surrogate_ceiling: None,
407 });
408
409 match dispatch_kv(state, session, plan).await {
410 Ok(resp) if resp.status == Status::Ok => {
411 let json: serde_json::Value = match sonic_rs::from_slice(&resp.payload) {
412 Ok(v) => v,
413 Err(e) => {
414 tracing::warn!(error = %e, "RESP DBSIZE: failed to decode KV scan payload");
415 return RespValue::err(format!("ERR dbsize decode failed: {e}"));
416 }
417 };
418 let count = match &json {
419 serde_json::Value::Array(arr) => arr.len() as i64,
420 _ => 0,
421 };
422 RespValue::integer(count)
423 }
424 _ => RespValue::integer(0),
425 }
426}
427
428async fn handle_info(_cmd: &RespCommand, session: &RespSession, _state: &SharedState) -> RespValue {
429 let info = format!(

Callers 1

executeFunction · 0.85

Calls 4

dispatch_kvFunction · 0.85
errFunction · 0.50
cloneMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected