diff --git a/src/store/updates.rs b/src/store/updates.rs index 521bb359e..22968738f 100644 --- a/src/store/updates.rs +++ b/src/store/updates.rs @@ -33,6 +33,16 @@ impl Updates { Ok(Some((number, last_data))) } + pub fn contains( + &self, + reader: &T, + update_id: u64, + ) -> Result + { + let update_id_bytes = update_id.to_be_bytes(); + self.updates.get(reader, update_id_bytes).map(|v| v.is_some()) + } + pub fn push_back( &self, writer: &mut rkv::Writer, diff --git a/src/store/updates_results.rs b/src/store/updates_results.rs index 22bd35976..0a99c18df 100644 --- a/src/store/updates_results.rs +++ b/src/store/updates_results.rs @@ -1,3 +1,4 @@ +use rkv::Value; use crate::update::UpdateResult; #[derive(Copy, Clone)] @@ -13,19 +14,27 @@ impl UpdatesResults { update_result: &UpdateResult, ) -> Result<(), rkv::StoreError> { - // let update = rmp_serde::to_vec_named(&addition)?; - - // WARN could not retrieve the last key/data entry of a tree... - // self.updates.get(writer, )?; - - unimplemented!() + let update_id_bytes = update_id.to_be_bytes(); + let update_result = bincode::serialize(&update_result).unwrap(); + let blob = Value::Blob(&update_result); + self.updates_results.put(writer, update_id_bytes, &blob) } pub fn update_result( + &self, reader: &T, update_id: u64, ) -> Result, rkv::StoreError> { - unimplemented!() + let update_id_bytes = update_id.to_be_bytes(); + + match self.updates_results.get(reader, update_id_bytes)? { + Some(Value::Blob(bytes)) => { + let update_result = bincode::deserialize(&bytes).unwrap(); + Ok(Some(update_result)) + }, + Some(value) => panic!("invalid type {:?}", value), + None => Ok(None), + } } } diff --git a/src/update/mod.rs b/src/update/mod.rs index da560c521..742c716fe 100644 --- a/src/update/mod.rs +++ b/src/update/mod.rs @@ -38,6 +38,32 @@ pub struct UpdateResult { pub detailed_duration: DetailedDuration, } +#[derive(Clone, Serialize, Deserialize)] +pub enum UpdateStatus { + Enqueued, + Processed(UpdateResult), + Unknown, +} + +pub fn update_status( + reader: &T, + updates_store: store::Updates, + updates_results_store: store::UpdatesResults, + update_id: u64, +) -> Result +{ + match updates_results_store.update_result(reader, update_id)? { + Some(result) => Ok(UpdateStatus::Processed(result)), + None => { + if updates_store.contains(reader, update_id)? { + Ok(UpdateStatus::Enqueued) + } else { + Ok(UpdateStatus::Unknown) + } + } + } +} + pub fn push_documents_addition( writer: &mut rkv::Writer, updates_store: store::Updates,