MeiliSearch/meilidb-core/src/store/updates_results.rs

42 lines
1.1 KiB
Rust
Raw Normal View History

2019-10-03 16:54:37 +02:00
use rkv::Value;
2019-10-03 17:33:15 +02:00
use crate::{update::UpdateResult, MResult};
2019-10-03 16:13:09 +02:00
#[derive(Copy, Clone)]
pub struct UpdatesResults {
pub(crate) updates_results: rkv::SingleStore,
}
impl UpdatesResults {
pub fn put_update_result(
&self,
writer: &mut rkv::Writer,
update_id: u64,
update_result: &UpdateResult,
2019-10-03 17:33:15 +02:00
) -> MResult<()>
2019-10-03 16:13:09 +02:00
{
2019-10-03 16:54:37 +02:00
let update_id_bytes = update_id.to_be_bytes();
2019-10-03 17:33:15 +02:00
let update_result = bincode::serialize(&update_result)?;
2019-10-03 16:54:37 +02:00
let blob = Value::Blob(&update_result);
2019-10-03 17:33:15 +02:00
self.updates_results.put(writer, update_id_bytes, &blob)?;
Ok(())
2019-10-03 16:13:09 +02:00
}
2019-10-04 10:21:09 +02:00
pub fn update_result(
2019-10-03 16:54:37 +02:00
&self,
2019-10-04 10:21:09 +02:00
reader: &impl rkv::Readable,
2019-10-03 16:13:09 +02:00
update_id: u64,
2019-10-03 17:33:15 +02:00
) -> MResult<Option<UpdateResult>>
2019-10-03 16:13:09 +02:00
{
2019-10-03 16:54:37 +02:00
let update_id_bytes = update_id.to_be_bytes();
match self.updates_results.get(reader, update_id_bytes)? {
Some(Value::Blob(bytes)) => {
2019-10-03 17:33:15 +02:00
let update_result = bincode::deserialize(&bytes)?;
2019-10-03 16:54:37 +02:00
Ok(Some(update_result))
},
Some(value) => panic!("invalid type {:?}", value),
None => Ok(None),
}
2019-10-03 16:13:09 +02:00
}
}