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

Method approx_bytes_for_collection

nodedb/src/engine/sparse/btree.rs:255–276  ·  view source on GitHub ↗

Approximate byte count for all documents in a single `(tenant_id, collection)` pair. Sums the raw value sizes via a redb range scan — O(N) in row count for a single read transaction. Best-effort: redb key overhead + secondary-index bytes are not counted. Used by the `_system.dropped_collections.size_bytes_estimate` column.

(&self, tenant_id: u64, collection: &str)

Source from the content-addressed store, hash-verified

253 /// bytes are not counted. Used by the
254 /// `_system.dropped_collections.size_bytes_estimate` column.
255 pub fn approx_bytes_for_collection(&self, tenant_id: u64, collection: &str) -> u64 {
256 let prefix = format!("{tenant_id}:{collection}:");
257 let end = format!("{tenant_id}:{collection}:\u{ffff}");
258 let read_txn = match self.db.begin_read() {
259 Ok(t) => t,
260 Err(_) => return 0,
261 };
262 let table = match read_txn.open_table(DOCUMENTS) {
263 Ok(t) => t,
264 Err(_) => return 0,
265 };
266 let mut total: u64 = 0;
267 let range = match table.range::<&str>(prefix.as_str()..end.as_str()) {
268 Ok(r) => r,
269 Err(_) => return 0,
270 };
271 for entry in range {
272 let Ok((_k, v)) = entry else { continue };
273 total = total.saturating_add(v.value().len() as u64);
274 }
275 total
276 }
277
278 /// Delete a document (tenant-scoped).
279 ///

Callers 1

Calls 2

as_strMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected