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

Method lookup

nodedb/src/engine/sparse/gsi.rs:237–267  ·  view source on GitHub ↗

Look up documents by GSI value. Returns entries pointing to primary locations.

(&self, index_name: &str, value: &str)

Source from the content-addressed store, hash-verified

235
236 /// Look up documents by GSI value. Returns entries pointing to primary locations.
237 pub fn lookup(&self, index_name: &str, value: &str) -> crate::Result<Vec<GsiEntry>> {
238 let key = format!("{index_name}:{value}");
239 let read_txn = self.db.begin_read().map_err(|e| crate::Error::Storage {
240 engine: "gsi".into(),
241 detail: format!("read: {e}"),
242 })?;
243 let table = read_txn
244 .open_table(GSI_TABLE)
245 .map_err(|e| crate::Error::Storage {
246 engine: "gsi".into(),
247 detail: format!("open entries: {e}"),
248 })?;
249
250 match table.get(key.as_str()) {
251 Ok(Some(guard)) => {
252 let entries: Vec<GsiEntry> = match zerompk::from_msgpack(guard.value()) {
253 Ok(v) => v,
254 Err(e) => {
255 tracing::warn!(index = %key, error = %e, "GSI lookup deserialization failed");
256 Vec::new()
257 }
258 };
259 Ok(entries)
260 }
261 Ok(None) => Ok(Vec::new()),
262 Err(e) => Err(crate::Error::Storage {
263 engine: "gsi".into(),
264 detail: format!("get: {e}"),
265 }),
266 }
267 }
268
269 /// List all GSIs declared for a collection.
270 pub fn list_indexes(&self, tenant_id: u64, collection: &str) -> crate::Result<Vec<GsiMeta>> {

Callers 4

create_and_lookupFunction · 0.45
update_replaces_entryFunction · 0.45
audit_dml_eventFunction · 0.45
unknown_collection_skipsFunction · 0.45

Calls 2

getMethod · 0.45
as_strMethod · 0.45

Tested by 3

create_and_lookupFunction · 0.36
update_replaces_entryFunction · 0.36
unknown_collection_skipsFunction · 0.36