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

Method observe_document

nodedb/src/engine/sparse/stats.rs:257–271  ·  view source on GitHub ↗

Update statistics incrementally for a document's fields. Called on every PointPut. Loads existing stats for each field, observes the new value, and persists.

(
        &self,
        tenant_id: u64,
        collection: &str,
        doc: &serde_json::Value,
    )

Source from the content-addressed store, hash-verified

255 /// Called on every PointPut. Loads existing stats for each field,
256 /// observes the new value, and persists.
257 pub fn observe_document(
258 &self,
259 tenant_id: u64,
260 collection: &str,
261 doc: &serde_json::Value,
262 ) -> crate::Result<()> {
263 if let Some(obj) = doc.as_object() {
264 for (field, value) in obj {
265 let mut stats = self.get(tenant_id, collection, field)?.unwrap_or_default();
266 stats.observe(Some(value));
267 self.put(tenant_id, collection, field, &stats)?;
268 }
269 }
270 Ok(())
271 }
272
273 /// Update statistics within an externally-owned write transaction.
274 ///

Callers

nothing calls this directly

Calls 4

as_objectMethod · 0.80
getMethod · 0.45
observeMethod · 0.45
putMethod · 0.45

Tested by

no test coverage detected