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

Method put

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

Persist updated statistics for a column.

(
        &self,
        tenant_id: u64,
        collection: &str,
        field: &str,
        stats: &ColumnStats,
    )

Source from the content-addressed store, hash-verified

213
214 /// Persist updated statistics for a column.
215 pub fn put(
216 &self,
217 tenant_id: u64,
218 collection: &str,
219 field: &str,
220 stats: &ColumnStats,
221 ) -> crate::Result<()> {
222 let key = format!("{tenant_id}:{collection}:{field}");
223 let bytes = zerompk::to_msgpack_vec(stats).map_err(|e| crate::Error::Storage {
224 engine: "stats".into(),
225 detail: format!("serialize: {e}"),
226 })?;
227 let write_txn = self.db.begin_write().map_err(|e| crate::Error::Storage {
228 engine: "stats".into(),
229 detail: format!("write txn: {e}"),
230 })?;
231 {
232 let mut table =
233 write_txn
234 .open_table(COLUMN_STATS)
235 .map_err(|e| crate::Error::Storage {
236 engine: "stats".into(),
237 detail: format!("open table: {e}"),
238 })?;
239 table
240 .insert(key.as_str(), bytes.as_slice())
241 .map_err(|e| crate::Error::Storage {
242 engine: "stats".into(),
243 detail: format!("insert: {e}"),
244 })?;
245 }
246 write_txn.commit().map_err(|e| crate::Error::Storage {
247 engine: "stats".into(),
248 detail: format!("commit: {e}"),
249 })?;
250 Ok(())
251 }
252
253 /// Update statistics incrementally for a document's fields.
254 ///

Callers 2

observe_documentMethod · 0.45
stats_store_roundtripFunction · 0.45

Calls 5

begin_writeMethod · 0.80
insertMethod · 0.45
as_strMethod · 0.45
as_sliceMethod · 0.45
commitMethod · 0.45

Tested by 1

stats_store_roundtripFunction · 0.36