Skip to content
Extraits de code Groupes Projets
Valider 4dc268a3 rédigé par Elliu's avatar Elliu
Parcourir les fichiers

NKDB: UpdateHandler: add method to know if we can upgrade from an epoch

parent cd0e2909
Aucune branche associée trouvée
Aucune étiquette associée trouvée
2 requêtes de fusion!206Use incremental upgrades when syncing epochs,!197Draft: Refactor the whole code.
...@@ -17,14 +17,20 @@ pub struct Epoch { ...@@ -17,14 +17,20 @@ pub struct Epoch {
/// Represent the data contained in an epoch. /// Represent the data contained in an epoch.
pub type EpochData = HashMap<KId, Kara>; pub type EpochData = HashMap<KId, Kara>;
pub struct EpochInfos(u64, u64); pub struct EpochInfos {
pub id: u64,
pub validity: u64,
}
/// Represent the keys of the epoch data, e.g. the ids of the kara in this epoch. /// Represent the keys of the epoch data, e.g. the ids of the kara in this epoch.
pub type EpochIds<'a> = hash_map::Keys<'a, KId, Kara>; pub type EpochIds<'a> = hash_map::Keys<'a, KId, Kara>;
impl From<kurisu_api::v2::Infos> for EpochInfos { impl From<kurisu_api::v2::Infos> for EpochInfos {
fn from(infos: kurisu_api::v2::Infos) -> Self { fn from(infos: kurisu_api::v2::Infos) -> Self {
Self(infos.epoch(), infos.epoch_validity()) Self {
id: infos.epoch(),
validity: infos.epoch_validity(),
}
} }
} }
...@@ -101,6 +107,11 @@ impl Epoch { ...@@ -101,6 +107,11 @@ impl Epoch {
self.id self.id
} }
/// Get the validity (version) of the epoch
pub fn validity(&self) -> u64 {
self.validity
}
/// Get the number of karas in the epoch. /// Get the number of karas in the epoch.
pub fn len(&self) -> usize { pub fn len(&self) -> usize {
self.data.len() self.data.len()
...@@ -112,7 +123,7 @@ impl Epoch { ...@@ -112,7 +123,7 @@ impl Epoch {
} }
pub fn set_infos(&mut self, infos: EpochInfos) { pub fn set_infos(&mut self, infos: EpochInfos) {
self.id = infos.0; self.id = infos.id;
self.validity = infos.1; self.validity = infos.validity;
} }
} }
...@@ -44,6 +44,19 @@ impl<'a, Storage: DatabaseStorage> UpdateHandler<'a, Storage> { ...@@ -44,6 +44,19 @@ impl<'a, Storage: DatabaseStorage> UpdateHandler<'a, Storage> {
} }
} }
/// If the epoch is updatable from using the repository described at infos,
/// then return Some(from), where from is the epoch to start updating from
/// (= the epoch id of last_epoch)
pub async fn recoverable_since(&self, infos: EpochInfos) -> Option<u64> {
match self.last_epoch {
None => None,
Some(last) if last.validity() != infos.validity => None,
Some(last) if last.num() < infos.id => Some(last.num()),
_ => None,
}
}
/// Set EpochInfos for last_epoch
pub async fn set_epoch_infos(&self, infos: EpochInfos) { pub async fn set_epoch_infos(&self, infos: EpochInfos) {
self.new_epoch.borrow_mut().content().set_infos(infos) self.new_epoch.borrow_mut().content().set_infos(infos)
} }
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter