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

Function extract_key_value

nodedb/src/event/cdc/buffer.rs:237–256  ·  view source on GitHub ↗
(event: &CdcEvent, key_field: &str)

Source from the content-addressed store, hash-verified

235}
236
237fn extract_key_value(event: &CdcEvent, key_field: &str) -> String {
238 let value = event.new_value.as_ref().or(event.old_value.as_ref());
239
240 if let Some(obj) = value.and_then(|v| v.as_object())
241 && let Some(val) = obj.get(key_field)
242 {
243 return match val {
244 serde_json::Value::String(s) => s.clone(),
245 other => other.to_string(),
246 };
247 }
248
249 tracing::warn!(
250 collection = %event.collection,
251 row_id = %event.row_id,
252 key_field,
253 "compaction key field not found in event, falling back to row_id"
254 );
255 event.row_id.clone()
256}
257
258#[cfg(test)]
259mod tests {

Callers 1

compactMethod · 0.85

Calls 6

as_objectMethod · 0.80
to_stringMethod · 0.80
orMethod · 0.45
as_refMethod · 0.45
getMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected