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

Method latest_for_array

nodedb/src/control/array_sync/snapshot_store.rs:167–191  ·  view source on GitHub ↗

Return the snapshot with the highest HLC for `array`, or `None` if none exist.

(&self, array: &str)

Source from the content-addressed store, hash-verified

165
166 /// Return the snapshot with the highest HLC for `array`, or `None` if none exist.
167 pub fn latest_for_array(&self, array: &str) -> Option<TileSnapshot> {
168 let prefix = name_prefix(array)?;
169 let txn = self.db.begin_read().ok()?;
170 let table = txn.open_table(SNAPSHOT_TABLE).ok()?;
171
172 // Scan the full range and collect prefix-matched keys; last = latest HLC.
173 let iter = table.iter().ok()?;
174 let mut last_bytes: Option<Vec<u8>> = None;
175 for entry in iter {
176 let Ok((k, v)) = entry else {
177 continue;
178 };
179 let key = k.value();
180 if key.starts_with(prefix.as_slice()) {
181 last_bytes = Some(v.value().to_vec());
182 }
183 }
184
185 let bytes = last_bytes?;
186 decode_snapshot(&bytes)
187 .map_err(|e| {
188 warn!(array = %array, error = %e, "snapshot_store: decode error on latest");
189 })
190 .ok()
191 }
192
193 /// Delete all snapshots for `array` whose `snapshot_hlc < older_than`.
194 ///

Callers 3

run_gcFunction · 0.80
serveMethod · 0.80

Calls 6

decode_snapshotFunction · 0.85
name_prefixFunction · 0.70
okMethod · 0.45
iterMethod · 0.45
as_sliceMethod · 0.45
to_vecMethod · 0.45

Tested by 1