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

Method get

nodedb/src/engine/sparse/doc_cache.rs:135–157  ·  view source on GitHub ↗

Look up a document in the cache. Returns `Some(&[u8])` on hit. Single HashMap lookup on the hot path — counters are bumped via `Cell` so the borrow checker permits `&self` here.

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

Source from the content-addressed store, hash-verified

133 /// Single HashMap lookup on the hot path — counters are bumped via
134 /// `Cell` so the borrow checker permits `&self` here.
135 pub fn get(
136 &self,
137 database_id: u64,
138 tenant_id: u64,
139 collection: &str,
140 document_id: &str,
141 ) -> Option<&[u8]> {
142 let key = Self::make_key(database_id, tenant_id, collection, document_id);
143 match self
144 .shards
145 .get(&database_id)
146 .and_then(|shard| shard.entries.get(&key))
147 {
148 Some(v) => {
149 self.hits.set(self.hits.get() + 1);
150 Some(v.as_slice())
151 }
152 None => {
153 self.misses.set(self.misses.get() + 1);
154 None
155 }
156 }
157 }
158
159 /// Insert or update a document in the cache (write-through).
160 pub fn put(

Callers 6

putMethod · 0.45
hit_rateMethod · 0.45
total_lookupsMethod · 0.45
hit_rate_trackingFunction · 0.45

Calls 3

make_keyFunction · 0.85
setMethod · 0.45
as_sliceMethod · 0.45