mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-26 14:54:27 +01:00
Make the Updates store work
This commit is contained in:
parent
0a731973b9
commit
af9fd9f552
@ -1,3 +1,5 @@
|
|||||||
|
use std::convert::TryInto;
|
||||||
|
use rkv::Value;
|
||||||
use crate::update::Update;
|
use crate::update::Update;
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
@ -6,18 +8,46 @@ pub struct Updates {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Updates {
|
impl Updates {
|
||||||
|
// TODO we should use the MDB_LAST op but
|
||||||
|
// it is not exposed by the rkv library
|
||||||
|
fn last_update_id<'a, T: rkv::Readable>(
|
||||||
|
&self,
|
||||||
|
reader: &'a T,
|
||||||
|
) -> Result<Option<(u64, Option<Value<'a>>)>, rkv::StoreError>
|
||||||
|
{
|
||||||
|
let mut last = None;
|
||||||
|
let iter = self.updates.iter_start(reader)?;
|
||||||
|
for result in iter {
|
||||||
|
let (key, data) = result?;
|
||||||
|
last = Some((key, data));
|
||||||
|
}
|
||||||
|
|
||||||
|
let (last_key, last_data) = match last {
|
||||||
|
Some(entry) => entry,
|
||||||
|
None => return Ok(None),
|
||||||
|
};
|
||||||
|
|
||||||
|
let array = last_key.try_into().unwrap();
|
||||||
|
let number = u64::from_be_bytes(array);
|
||||||
|
|
||||||
|
Ok(Some((number, last_data)))
|
||||||
|
}
|
||||||
|
|
||||||
pub fn push_back(
|
pub fn push_back(
|
||||||
&self,
|
&self,
|
||||||
writer: &mut rkv::Writer,
|
writer: &mut rkv::Writer,
|
||||||
update: &Update,
|
update: &Update,
|
||||||
) -> Result<u64, rkv::StoreError>
|
) -> Result<u64, rkv::StoreError>
|
||||||
{
|
{
|
||||||
// let update = rmp_serde::to_vec_named(&addition)?;
|
let last_update_id = self.last_update_id(writer)?;
|
||||||
|
let last_update_id = last_update_id.map_or(0, |(n, _)| n + 1);
|
||||||
|
let last_update_id_bytes = last_update_id.to_be_bytes();
|
||||||
|
|
||||||
// WARN could not retrieve the last key/data entry of a tree...
|
let update = rmp_serde::to_vec_named(&update).unwrap();
|
||||||
// self.updates.get(writer, )?;
|
let blob = Value::Blob(&update);
|
||||||
|
self.updates.put(writer, last_update_id_bytes, &blob)?;
|
||||||
|
|
||||||
unimplemented!()
|
Ok(last_update_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn pop_back(
|
pub fn pop_back(
|
||||||
@ -25,6 +55,18 @@ impl Updates {
|
|||||||
writer: &mut rkv::Writer,
|
writer: &mut rkv::Writer,
|
||||||
) -> Result<Option<(u64, Update)>, rkv::StoreError>
|
) -> Result<Option<(u64, Update)>, rkv::StoreError>
|
||||||
{
|
{
|
||||||
unimplemented!()
|
let (last_id, last_data) = match self.last_update_id(writer)? {
|
||||||
|
Some(entry) => entry,
|
||||||
|
None => return Ok(None),
|
||||||
|
};
|
||||||
|
|
||||||
|
match last_data {
|
||||||
|
Some(Value::Blob(bytes)) => {
|
||||||
|
let update = rmp_serde::from_read_ref(&bytes).unwrap();
|
||||||
|
Ok(Some((last_id, update)))
|
||||||
|
},
|
||||||
|
Some(value) => panic!("invalid type {:?}", value),
|
||||||
|
None => Ok(None),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user