feat: Introduce the updated_documents methods

This commit is contained in:
Clément Renault 2019-02-18 18:01:40 +01:00
parent 264fffa826
commit a0c4ec0be0
No known key found for this signature in database
GPG Key ID: 0151CDAB43460DAE
3 changed files with 26 additions and 12 deletions

View File

@ -21,6 +21,8 @@ use crate::shared_data_cursor::FromSharedDataCursor;
use crate::write_to_bytes::WriteToBytes;
use crate::DocumentId;
use self::update::{ReadIndexEvent, ReadRankedMapEvent};
pub use self::document_key::{DocumentKey, DocumentKeyAttr};
pub use self::view::{DatabaseView, DocumentIter};
pub use self::update::Update;
@ -55,8 +57,6 @@ where D: Deref<Target=DB>
fn retrieve_data_index<D>(snapshot: &Snapshot<D>) -> Result<Index, Box<Error>>
where D: Deref<Target=DB>
{
use self::update::ReadIndexEvent::{self, *};
let start = Instant::now();
let vector = snapshot.get(DATA_INDEX)?;
info!("loading index from kv-store took {:.2?}", start.elapsed());
@ -68,10 +68,8 @@ where D: Deref<Target=DB>
let bytes = vector.as_ref().to_vec();
info!("index size is {}B", SizeFormatterBinary::new(bytes.len() as u64));
let index = match ReadIndexEvent::from_bytes(bytes)? {
RemovedDocuments(_) => panic!("BUG: RemovedDocument event retrieved"),
UpdatedDocuments(index) => index,
};
let event = ReadIndexEvent::from_bytes(bytes)?;
let index = event.updated_documents().expect("BUG: invalid event deserialized");
info!("loading index from bytes took {:.2?}", start.elapsed());
@ -84,8 +82,6 @@ where D: Deref<Target=DB>
fn retrieve_data_ranked_map<D>(snapshot: &Snapshot<D>) -> Result<RankedMap, Box<Error>>
where D: Deref<Target=DB>,
{
use self::update::ReadRankedMapEvent::{self, *};
let start = Instant::now();
let vector = snapshot.get(DATA_RANKED_MAP)?;
info!("loading ranked map from kv-store took {:.2?}", start.elapsed());
@ -97,10 +93,8 @@ where D: Deref<Target=DB>,
let bytes = vector.as_ref().to_vec();
info!("ranked map size is {}B", SizeFormatterBinary::new(bytes.len() as u64));
let ranked_map = match ReadRankedMapEvent::from_bytes(bytes)? {
RemovedDocuments(_) => panic!("BUG: RemovedDocument event retrieved"),
UpdatedDocuments(ranked_map) => ranked_map,
};
let event = ReadRankedMapEvent::from_bytes(bytes)?;
let ranked_map = event.updated_documents().expect("BUG: invalid event deserialized");
info!("loading ranked map from bytes took {:.2?}", start.elapsed());

View File

@ -32,6 +32,16 @@ pub enum ReadIndexEvent {
UpdatedDocuments(Index),
}
impl ReadIndexEvent {
pub fn updated_documents(self) -> Option<Index> {
use ReadIndexEvent::*;
match self {
RemovedDocuments(_) => None,
UpdatedDocuments(index) => Some(index),
}
}
}
impl FromSharedDataCursor for ReadIndexEvent {
type Error = Box<Error>;

View File

@ -32,6 +32,16 @@ pub enum ReadRankedMapEvent {
UpdatedDocuments(RankedMap),
}
impl ReadRankedMapEvent {
pub fn updated_documents(self) -> Option<RankedMap> {
use ReadRankedMapEvent::*;
match self {
RemovedDocuments(_) => None,
UpdatedDocuments(ranked_map) => Some(ranked_map),
}
}
}
impl FromSharedDataCursor for ReadRankedMapEvent {
type Error = Box<Error>;