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

Method save

nodedb/src/control/array_sync/outbound/subscriber_state.rs:204–233  ·  view source on GitHub ↗

Persist a subscriber cursor.

(&self, state: &ArraySubscriberState)

Source from the content-addressed store, hash-verified

202
203 /// Persist a subscriber cursor.
204 fn save(&self, state: &ArraySubscriberState) -> crate::Result<()> {
205 let key = Self::cursor_key(&state.session_id, &state.array_name);
206 let bytes = zerompk::to_msgpack_vec(state).map_err(|e| crate::Error::Storage {
207 engine: "array_sync".into(),
208 detail: format!("subscriber_store save encode: {e}"),
209 })?;
210 let txn = self.db.begin_write().map_err(|e| crate::Error::Storage {
211 engine: "array_sync".into(),
212 detail: format!("subscriber_store save begin_write: {e}"),
213 })?;
214 {
215 let mut table = txn
216 .open_table(CURSOR_TABLE)
217 .map_err(|e| crate::Error::Storage {
218 engine: "array_sync".into(),
219 detail: format!("subscriber_store save open_table: {e}"),
220 })?;
221 table
222 .insert(key.as_str(), bytes.as_slice())
223 .map_err(|e| crate::Error::Storage {
224 engine: "array_sync".into(),
225 detail: format!("subscriber_store save insert: {e}"),
226 })?;
227 }
228 txn.commit().map_err(|e| crate::Error::Storage {
229 engine: "array_sync".into(),
230 detail: format!("subscriber_store save commit: {e}"),
231 })?;
232 Ok(())
233 }
234
235 /// Load a subscriber cursor, returning `None` if not found.
236 fn load(&self, session_id: &str, array_name: &str) -> Option<ArraySubscriberState> {

Callers 1

mark_sentMethod · 0.45

Calls 5

begin_writeMethod · 0.80
insertMethod · 0.45
as_strMethod · 0.45
as_sliceMethod · 0.45
commitMethod · 0.45

Tested by

no test coverage detected