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

Function bump

nodedb/src/engine/sparse/fts_redb/backend/stats.rs:53–83  ·  view source on GitHub ↗
(backend: &RedbFtsBackend, tid: u64, collection: &str, delta: i64)

Source from the content-addressed store, hash-verified

51}
52
53fn bump(backend: &RedbFtsBackend, tid: u64, collection: &str, delta: i64) -> crate::Result<()> {
54 let write_txn = backend
55 .db
56 .begin_write()
57 .map_err(|e| redb_err("write txn", e))?;
58 {
59 let mut table = write_txn
60 .open_table(STATS)
61 .map_err(|e| redb_err("open stats", e))?;
62 let (mut count, mut total) = table
63 .get((tid, collection))
64 .ok()
65 .flatten()
66 .and_then(|v| zerompk::from_msgpack::<(u32, u64)>(v.value()).ok())
67 .unwrap_or((0, 0));
68 if delta > 0 {
69 count += 1;
70 total += delta as u64;
71 } else {
72 count = count.saturating_sub(1);
73 total = total.saturating_sub((-delta) as u64);
74 }
75 let bytes =
76 zerompk::to_msgpack_vec(&(count, total)).map_err(|e| redb_err("serialize stats", e))?;
77 table
78 .insert((tid, collection), bytes.as_slice())
79 .map_err(|e| redb_err("insert stats", e))?;
80 }
81 write_txn.commit().map_err(|e| redb_err("commit", e))?;
82 Ok(())
83}

Callers 2

incrementFunction · 0.85
decrementFunction · 0.85

Calls 7

begin_writeMethod · 0.80
redb_errFunction · 0.70
okMethod · 0.45
getMethod · 0.45
insertMethod · 0.45
as_sliceMethod · 0.45
commitMethod · 0.45

Tested by

no test coverage detected