mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-30 00:34:26 +01:00
Make the UpdatesResults store work
This commit is contained in:
parent
af9fd9f552
commit
00c70d3cb5
@ -33,6 +33,16 @@ impl Updates {
|
||||
Ok(Some((number, last_data)))
|
||||
}
|
||||
|
||||
pub fn contains<T: rkv::Readable>(
|
||||
&self,
|
||||
reader: &T,
|
||||
update_id: u64,
|
||||
) -> Result<bool, rkv::StoreError>
|
||||
{
|
||||
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,
|
||||
|
@ -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<T: rkv::Readable>(
|
||||
&self,
|
||||
reader: &T,
|
||||
update_id: u64,
|
||||
) -> Result<Option<UpdateResult>, 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),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<T: rkv::Readable>(
|
||||
reader: &T,
|
||||
updates_store: store::Updates,
|
||||
updates_results_store: store::UpdatesResults,
|
||||
update_id: u64,
|
||||
) -> Result<UpdateStatus, rkv::StoreError>
|
||||
{
|
||||
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<D: serde::Serialize>(
|
||||
writer: &mut rkv::Writer,
|
||||
updates_store: store::Updates,
|
||||
|
Loading…
Reference in New Issue
Block a user