Fix latest key backup determination.
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
@@ -106,16 +106,23 @@ pub async fn update_backup<'a>(
|
|||||||
pub async fn get_latest_backup_version(&self, user_id: &UserId) -> Result<String> {
|
pub async fn get_latest_backup_version(&self, user_id: &UserId) -> Result<String> {
|
||||||
type Key<'a> = (&'a UserId, &'a str);
|
type Key<'a> = (&'a UserId, &'a str);
|
||||||
|
|
||||||
let last_possible_key = (user_id, u64::MAX);
|
let key = (user_id, Interfix);
|
||||||
self.db
|
let mut versions: Vec<_> = self
|
||||||
|
.db
|
||||||
.backupid_algorithm
|
.backupid_algorithm
|
||||||
.rev_keys_from(&last_possible_key)
|
.keys_from(&key)
|
||||||
.ignore_err()
|
.ignore_err()
|
||||||
.ready_take_while(|(user_id_, _): &Key<'_>| *user_id_ == user_id)
|
.ready_take_while(|(user_id_, _): &Key<'_>| *user_id_ == user_id)
|
||||||
.map(|(_, version): Key<'_>| version.to_owned())
|
.ready_filter_map(|(_, version): Key<'_>| version.parse::<u64>().ok())
|
||||||
.next()
|
.collect()
|
||||||
.await
|
.await;
|
||||||
.ok_or_else(|| err!(Request(NotFound("No backup versions found"))))
|
|
||||||
|
versions.sort_unstable();
|
||||||
|
let Some(latest) = versions.last() else {
|
||||||
|
return Err!(Request(NotFound("No backup versions found")));
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(latest.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[implement(Service)]
|
#[implement(Service)]
|
||||||
@@ -123,19 +130,16 @@ pub async fn get_latest_backup(
|
|||||||
&self,
|
&self,
|
||||||
user_id: &UserId,
|
user_id: &UserId,
|
||||||
) -> Result<(String, Raw<BackupAlgorithm>)> {
|
) -> Result<(String, Raw<BackupAlgorithm>)> {
|
||||||
type Key<'a> = (&'a UserId, &'a str);
|
let version = self.get_latest_backup_version(user_id).await?;
|
||||||
type KeyVal<'a> = (Key<'a>, Raw<BackupAlgorithm>);
|
|
||||||
|
|
||||||
let last_possible_key = (user_id, u64::MAX);
|
let key = (user_id, version.as_str());
|
||||||
self.db
|
self.db
|
||||||
.backupid_algorithm
|
.backupid_algorithm
|
||||||
.rev_stream_from(&last_possible_key)
|
.qry(&key)
|
||||||
.ignore_err()
|
|
||||||
.ready_take_while(|((user_id_, _), _): &KeyVal<'_>| *user_id_ == user_id)
|
|
||||||
.map(|((_, version), algorithm): KeyVal<'_>| (version.to_owned(), algorithm))
|
|
||||||
.next()
|
|
||||||
.await
|
.await
|
||||||
.ok_or_else(|| err!(Request(NotFound("No backup found"))))
|
.deserialized()
|
||||||
|
.map(|algorithm| (version, algorithm))
|
||||||
|
.map_err(|e| err!(Request(NotFound("No backup found: {e}"))))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[implement(Service)]
|
#[implement(Service)]
|
||||||
|
|||||||
Reference in New Issue
Block a user