Update the iter_metas UpdateStore method

This commit is contained in:
Clément Renault 2020-10-19 13:56:32 +02:00
parent 65e32fecb1
commit 8bfa43f9a7
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4

View File

@ -147,28 +147,24 @@ impl<M: 'static> UpdateStore<M> {
} }
} }
/// Iterate over the pending and the processed metas one after the other, /// Execute the user defined function with both meta-store iterators, the first
/// calling the user defined callback for each meta. /// iterator is the *pending* meta one and the secind is the *processed* meta one.
pub fn iter_meta<F>(&self, mut f: F) -> heed::Result<()> pub fn iter_metas<F, T>(&self, mut f: F) -> heed::Result<T>
where where
M: for<'a> Deserialize<'a>, M: for<'a> Deserialize<'a>,
F: FnMut(u64, M), F: for<'a> FnMut(
heed::RoIter<'a, OwnedType<BEU64>, SerdeJson<M>>,
heed::RoIter<'a, OwnedType<BEU64>, SerdeJson<M>>,
) -> heed::Result<T>,
{ {
let rtxn = self.env.read_txn()?; let rtxn = self.env.read_txn()?;
// We iterate over the pending updates. // We get both the pending and processed meta iterators.
for result in self.pending_meta.iter(&rtxn)? { let pending_iter = self.pending_meta.iter(&rtxn)?;
let (key, meta) = result?; let processed_iter = self.processed_meta.iter(&rtxn)?;
(f)(key.get(), meta);
}
// We iterate over the processed updates. // We execute the user defined function with both iterators.
for result in self.processed_meta.iter(&rtxn)? { (f)(pending_iter, processed_iter)
let (key, meta) = result?;
(f)(key.get(), meta);
}
Ok(())
} }
/// Returns the update associated meta or `None` if the update deosn't exist. /// Returns the update associated meta or `None` if the update deosn't exist.