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

Method batch_put

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

Batch insert or update multiple documents in a single redb transaction.

(
        &self,
        tenant_id: u64,
        collection: &str,
        documents: &[(&str, &[u8])],
    )

Source from the content-addressed store, hash-verified

185
186 /// Batch insert or update multiple documents in a single redb transaction.
187 pub fn batch_put(
188 &self,
189 tenant_id: u64,
190 collection: &str,
191 documents: &[(&str, &[u8])],
192 ) -> crate::Result<()> {
193 if documents.is_empty() {
194 return Ok(());
195 }
196
197 let write_txn = self
198 .db
199 .begin_write()
200 .map_err(|e| redb_err("batch write txn", e))?;
201 {
202 let mut table = write_txn
203 .open_table(DOCUMENTS)
204 .map_err(|e| redb_err("open table", e))?;
205
206 for (document_id, value) in documents {
207 with_tenant_key(
208 tenant_id,
209 collection,
210 document_id,
211 |key| -> crate::Result<()> {
212 table
213 .insert(key, *value)
214 .map_err(|e| redb_err("batch insert", e))?;
215 Ok(())
216 },
217 )?;
218 }
219 }
220 write_txn
221 .commit()
222 .map_err(|e| redb_err("batch commit", e))?;
223
224 debug!(collection, count = documents.len(), "batch document put");
225 Ok(())
226 }
227
228 /// Point lookup: retrieve a document by collection + document_id (tenant-scoped).
229 pub fn get(

Callers

nothing calls this directly

Calls 6

with_tenant_keyFunction · 0.85
begin_writeMethod · 0.80
redb_errFunction · 0.70
is_emptyMethod · 0.45
insertMethod · 0.45
commitMethod · 0.45

Tested by

no test coverage detected