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

Method execute_graph_neighbors_multi

nodedb/src/data/executor/handlers/graph.rs:335–409  ·  view source on GitHub ↗
(
        &self,
        task: &ExecutionTask,
        tid: u64,
        node_ids: &[String],
        edge_label: &Option<String>,
        direction: crate::engine::graph::edge_store::Direction,
     

Source from the content-addressed store, hash-verified

333 }
334
335 pub(in crate::data::executor) fn execute_graph_neighbors_multi(
336 &self,
337 task: &ExecutionTask,
338 tid: u64,
339 node_ids: &[String],
340 edge_label: &Option<String>,
341 direction: crate::engine::graph::edge_store::Direction,
342 max_results: u32,
343 ) -> Response {
344 debug!(
345 core = self.core_id,
346 tid,
347 count = node_ids.len(),
348 ?edge_label,
349 ?direction,
350 max_results,
351 "graph neighbors multi"
352 );
353 let cap: usize = if max_results == 0 {
354 usize::MAX
355 } else {
356 max_results as usize
357 };
358 let mut owned: Vec<(String, String, String)> =
359 Vec::with_capacity(node_ids.len().min(cap) * 4);
360 let mut truncated = false;
361 if let Some(partition) = self.csr_partition(tid) {
362 'outer: for raw_src in node_ids {
363 let neighbors = partition.neighbors(raw_src, edge_label.as_deref(), direction);
364 for (label, node) in neighbors {
365 if owned.len() >= cap {
366 truncated = true;
367 break 'outer;
368 }
369 owned.push((raw_src.clone(), label, node));
370 }
371 }
372 }
373 let entries: Vec<super::super::response_codec::NeighborMultiEntry> = owned
374 .iter()
375 .map(
376 |(src, label, node)| super::super::response_codec::NeighborMultiEntry {
377 src: src.as_str(),
378 label: label.as_str(),
379 node: node.as_str(),
380 },
381 )
382 .collect();
383 if let Some(ref m) = self.metrics {
384 m.record_graph_traversal();
385 }
386 match super::super::response_codec::encode(&entries) {
387 Ok(payload) => {
388 if truncated {
389 self.response_partial(task, payload)
390 } else {
391 self.response_with_payload(task, payload)
392 }

Callers 1

dispatch_graphMethod · 0.80

Calls 14

csr_partitionMethod · 0.80
collectMethod · 0.80
response_partialMethod · 0.80
response_with_payloadMethod · 0.80
response_errorMethod · 0.80
to_stringMethod · 0.80
encodeFunction · 0.50
lenMethod · 0.45
neighborsMethod · 0.45
pushMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected