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

Method maybe_register_edge

nodedb/src/data/executor/handlers/point/insert.rs:121–179  ·  view source on GitHub ↗

Cross-engine graph overlay: when a schemaless document carries the reserved `_from` / `_to` (and optional `_type`) fields, mirror it as an edge in the CSR adjacency index and the edge store. Without this hook, `MATCH ...` and `GRAPH ALGO ...` would never see edges that were inserted via plain document INSERT.

(
        &mut self,
        tid: u64,
        collection: &str,
        surrogate: Surrogate,
        value: &[u8],
    )

Source from the content-addressed store, hash-verified

119 /// hook, `MATCH ...` and `GRAPH ALGO ...` would never see edges that
120 /// were inserted via plain document INSERT.
121 fn maybe_register_edge(
122 &mut self,
123 tid: u64,
124 collection: &str,
125 surrogate: Surrogate,
126 value: &[u8],
127 ) {
128 let doc =
129 match crate::data::executor::handlers::document::read::decode::decode_scanned_document(
130 value, None,
131 ) {
132 serde_json::Value::Object(m) => m,
133 _ => return,
134 };
135 let src = match doc.get("_from").and_then(|v| v.as_str()) {
136 Some(s) => s.to_string(),
137 None => return,
138 };
139 let dst = match doc.get("_to").and_then(|v| v.as_str()) {
140 Some(s) => s.to_string(),
141 None => return,
142 };
143 let label = doc
144 .get("_type")
145 .and_then(|v| v.as_str())
146 .unwrap_or("edge")
147 .to_string();
148 let weight = doc.get("weight").and_then(|v| v.as_f64()).unwrap_or(1.0);
149
150 let ord = self.hlc.next_ordinal();
151 let valid_from_ms = nodedb_types::ordinal_to_ms(ord);
152 use crate::engine::graph::edge_store::EdgeRef;
153 if let Err(e) = self.edge_store.put_edge_versioned(
154 EdgeRef::new(
155 crate::types::TenantId::new(tid),
156 collection,
157 &src,
158 &label,
159 &dst,
160 ),
161 &[],
162 ord,
163 valid_from_ms,
164 i64::MAX,
165 ) {
166 tracing::debug!(err = %e, %src, %dst, %label, %collection, "edge store write failed during graph overlay registration");
167 }
168 let partition = self.csr_partition_mut(tid);
169 let csr_result = if (weight - 1.0).abs() > f64::EPSILON {
170 partition.add_edge_weighted(&src, &label, &dst, weight)
171 } else {
172 partition.add_edge(&src, &label, &dst)
173 };
174 if let Err(e) = csr_result {
175 tracing::debug!(err = %e, %src, %dst, %label, %collection, "CSR partition write failed during graph overlay registration");
176 }
177 partition.set_node_surrogate(&src, Surrogate::ZERO);
178 partition.set_node_surrogate(&dst, surrogate);

Callers 1

execute_point_insertMethod · 0.80

Calls 12

decode_scanned_documentFunction · 0.85
ordinal_to_msFunction · 0.85
to_stringMethod · 0.80
next_ordinalMethod · 0.80
put_edge_versionedMethod · 0.80
csr_partition_mutMethod · 0.80
add_edge_weightedMethod · 0.80
add_edgeMethod · 0.80
set_node_surrogateMethod · 0.80
getMethod · 0.45
as_strMethod · 0.45
as_f64Method · 0.45

Tested by

no test coverage detected