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

Method scan_documents

nodedb/src/engine/sparse/btree_scan.rs:14–47  ·  view source on GitHub ↗

Scan documents in a collection (reads DOCUMENTS table, not INDEXES). Returns `(document_id, document_bytes)` pairs for all documents in the collection, up to `limit`. Use for full table scans and post-scan filtering.

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

Source from the content-addressed store, hash-verified

12 /// Returns `(document_id, document_bytes)` pairs for all documents in the
13 /// collection, up to `limit`. Use for full table scans and post-scan filtering.
14 pub fn scan_documents(
15 &self,
16 tenant_id: u64,
17 collection: &str,
18 limit: usize,
19 ) -> crate::Result<Vec<(String, Vec<u8>)>> {
20 let prefix = format!("{tenant_id}:{collection}:");
21 let end = format!("{tenant_id}:{collection}:\u{ffff}");
22
23 let read_txn = self.db.begin_read().map_err(|e| redb_err("read txn", e))?;
24 let table = read_txn
25 .open_table(DOCUMENTS)
26 .map_err(|e| redb_err("open table", e))?;
27
28 let range = table
29 .range(prefix.as_str()..end.as_str())
30 .map_err(|e| redb_err("doc range", e))?;
31
32 let mut results = Vec::with_capacity(limit.min(256));
33 for entry in range {
34 if results.len() >= limit {
35 break;
36 }
37 let entry = entry.map_err(|e| redb_err("doc entry", e))?;
38 let key = entry.0.value().to_string();
39 // Extract document_id from key format "{tenant}:{collection}:{doc_id}"
40 let doc_id = key.strip_prefix(&prefix).unwrap_or(&key).to_string();
41 let value = entry.1.value().to_vec();
42 results.push((doc_id, value));
43 }
44
45 debug!(collection, count = results.len(), "document scan");
46 Ok(results)
47 }
48
49 /// Scan documents in chunks, calling `handler` for each chunk.
50 ///

Callers 7

scan_sparseMethod · 0.80
convert_to_strictMethod · 0.80
execute_document_scanMethod · 0.80

Calls 7

to_stringMethod · 0.80
redb_errFunction · 0.70
rangeMethod · 0.45
as_strMethod · 0.45
lenMethod · 0.45
to_vecMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected