2019-10-18 13:05:28 +02:00
|
|
|
use super::BEU64;
|
2019-11-26 16:12:06 +01:00
|
|
|
use crate::database::UpdateT;
|
2019-10-31 11:13:37 +01:00
|
|
|
use crate::update::ProcessedUpdateResult;
|
2019-11-12 16:18:53 +01:00
|
|
|
use heed::types::{OwnedType, SerdeJson};
|
2019-10-21 12:05:53 +02:00
|
|
|
use heed::Result as ZResult;
|
2019-10-03 16:13:09 +02:00
|
|
|
|
|
|
|
#[derive(Copy, Clone)]
|
|
|
|
pub struct UpdatesResults {
|
2019-11-12 18:00:47 +01:00
|
|
|
pub(crate) updates_results: heed::Database<OwnedType<BEU64>, SerdeJson<ProcessedUpdateResult>>,
|
2019-10-03 16:13:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl UpdatesResults {
|
2019-11-26 16:12:06 +01:00
|
|
|
pub fn last_update(
|
2019-10-31 11:13:37 +01:00
|
|
|
self,
|
2019-11-26 16:12:06 +01:00
|
|
|
reader: &heed::RoTxn<UpdateT>,
|
2019-10-31 11:13:37 +01:00
|
|
|
) -> ZResult<Option<(u64, ProcessedUpdateResult)>> {
|
2019-10-16 17:05:24 +02:00
|
|
|
match self.updates_results.last(reader)? {
|
|
|
|
Some((key, data)) => Ok(Some((key.get(), data))),
|
|
|
|
None => Ok(None),
|
2019-10-07 16:16:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-03 16:13:09 +02:00
|
|
|
pub fn put_update_result(
|
2019-10-18 13:21:41 +02:00
|
|
|
self,
|
2019-11-26 16:12:06 +01:00
|
|
|
writer: &mut heed::RwTxn<UpdateT>,
|
2019-10-03 16:13:09 +02:00
|
|
|
update_id: u64,
|
2019-10-31 11:13:37 +01:00
|
|
|
update_result: &ProcessedUpdateResult,
|
2019-10-18 13:05:28 +02:00
|
|
|
) -> ZResult<()> {
|
2019-10-16 17:05:24 +02:00
|
|
|
let update_id = BEU64::new(update_id);
|
|
|
|
self.updates_results.put(writer, &update_id, update_result)
|
2019-10-03 16:13:09 +02:00
|
|
|
}
|
|
|
|
|
2019-10-04 10:21:09 +02:00
|
|
|
pub fn update_result(
|
2019-10-18 13:21:41 +02:00
|
|
|
self,
|
2019-11-26 16:12:06 +01:00
|
|
|
reader: &heed::RoTxn<UpdateT>,
|
2019-10-03 16:13:09 +02:00
|
|
|
update_id: u64,
|
2019-10-31 11:13:37 +01:00
|
|
|
) -> ZResult<Option<ProcessedUpdateResult>> {
|
2019-10-16 17:05:24 +02:00
|
|
|
let update_id = BEU64::new(update_id);
|
|
|
|
self.updates_results.get(reader, &update_id)
|
2019-10-03 16:13:09 +02:00
|
|
|
}
|
2019-11-06 10:49:13 +01:00
|
|
|
|
2019-11-26 16:12:06 +01:00
|
|
|
pub fn clear(self, writer: &mut heed::RwTxn<UpdateT>) -> ZResult<()> {
|
2019-11-06 10:49:13 +01:00
|
|
|
self.updates_results.clear(writer)
|
|
|
|
}
|
2019-10-03 16:13:09 +02:00
|
|
|
}
|