From 323a3c746d385ba4833bd98a1c965579b7da594e Mon Sep 17 00:00:00 2001 From: boxbeam Date: Fri, 5 Apr 2024 12:01:16 -0400 Subject: [PATCH] Make update_latest_version --- ee/tabby-webserver/src/hub/api.rs | 12 +----------- ee/tabby-webserver/src/path.rs | 2 +- ee/tabby-webserver/src/repositories/resolve.rs | 7 ++++--- 3 files changed, 6 insertions(+), 15 deletions(-) diff --git a/ee/tabby-webserver/src/hub/api.rs b/ee/tabby-webserver/src/hub/api.rs index 15920a722994..6a1f9cf7aaa8 100644 --- a/ee/tabby-webserver/src/hub/api.rs +++ b/ee/tabby-webserver/src/hub/api.rs @@ -221,17 +221,7 @@ impl RepositoryAccess for SchedulerClient { return; } }; - let old_version = match cache.latest_version() { - Ok(v) => v, - Err(e) => { - error!("Failed to get next repository cache version: {e}"); - return; - } - }; - if let Err(e) = cache - .set_version(version) - .and_then(|_| cache.clear_versions_under(old_version)) - { + if let Err(e) = cache.update_latest_version(version) { error!("Failed to update repository cache version: {e}"); } } diff --git a/ee/tabby-webserver/src/path.rs b/ee/tabby-webserver/src/path.rs index 47ccb4625d4b..bef7bc978350 100644 --- a/ee/tabby-webserver/src/path.rs +++ b/ee/tabby-webserver/src/path.rs @@ -1,5 +1,5 @@ use std::path::PathBuf; pub fn repository_meta_db() -> PathBuf { - tabby_common::path::tabby_root().join("repositories.kv") + tabby_common::path::tabby_root().join("ee/repositories.kv") } diff --git a/ee/tabby-webserver/src/repositories/resolve.rs b/ee/tabby-webserver/src/repositories/resolve.rs index 80c787af8cdb..0b761494b074 100644 --- a/ee/tabby-webserver/src/repositories/resolve.rs +++ b/ee/tabby-webserver/src/repositories/resolve.rs @@ -41,7 +41,7 @@ impl RepositoryCache { pub fn latest_version(&self) -> Result { let bucket: Bucket<_, String> = self.cache.bucket(Some(META_BUCKET))?; if !bucket.contains(&META_BUCKET_VERSION_KEY.to_string())? { - self.set_version(self.get_next_version()?)?; + self.update_latest_version(self.get_next_version()?)?; } Ok(bucket .get(&META_BUCKET_VERSION_KEY.to_string())? @@ -49,9 +49,10 @@ impl RepositoryCache { .parse()?) } - pub fn set_version(&self, version: u64) -> Result<()> { + pub fn update_latest_version(&self, version: u64) -> Result<()> { let bucket = self.cache.bucket(Some(META_BUCKET))?; bucket.set(&META_BUCKET_VERSION_KEY.to_string(), &version.to_string())?; + self.clear_versions_under(version)?; Ok(()) } @@ -76,7 +77,7 @@ impl RepositoryCache { let Ok(version) = version.parse::() else { continue; }; - if version <= old_version { + if version < old_version { self.cache.drop_bucket(bucket)?; } }