Skip to content

Commit

Permalink
Make update_latest_version
Browse files Browse the repository at this point in the history
  • Loading branch information
boxbeam committed Apr 5, 2024
1 parent 443b281 commit 323a3c7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 15 deletions.
12 changes: 1 addition & 11 deletions ee/tabby-webserver/src/hub/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,17 +221,7 @@ impl RepositoryAccess for SchedulerClient {
return;

Check warning on line 221 in ee/tabby-webserver/src/hub/api.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/hub/api.rs#L216-L221

Added lines #L216 - L221 were not covered by tests
}
};
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}");
}
}

Check warning on line 227 in ee/tabby-webserver/src/hub/api.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/hub/api.rs#L224-L227

Added lines #L224 - L227 were not covered by tests
Expand Down
2 changes: 1 addition & 1 deletion ee/tabby-webserver/src/path.rs
Original file line number Diff line number Diff line change
@@ -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")
}

Check warning on line 5 in ee/tabby-webserver/src/path.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/path.rs#L3-L5

Added lines #L3 - L5 were not covered by tests
7 changes: 4 additions & 3 deletions ee/tabby-webserver/src/repositories/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,18 @@ impl RepositoryCache {
pub fn latest_version(&self) -> Result<u64> {
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())?
.expect("Cache version must always be set")
.parse()?)
}

Check warning on line 50 in ee/tabby-webserver/src/repositories/resolve.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/repositories/resolve.rs#L41-L50

Added lines #L41 - L50 were not covered by tests

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)?;

Check warning on line 55 in ee/tabby-webserver/src/repositories/resolve.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/repositories/resolve.rs#L52-L55

Added lines #L52 - L55 were not covered by tests
Ok(())
}

Expand All @@ -76,7 +77,7 @@ impl RepositoryCache {
let Ok(version) = version.parse::<u64>() else {
continue;

Check warning on line 78 in ee/tabby-webserver/src/repositories/resolve.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/repositories/resolve.rs#L77-L78

Added lines #L77 - L78 were not covered by tests
};
if version <= old_version {
if version < old_version {
self.cache.drop_bucket(bucket)?;

Check warning on line 81 in ee/tabby-webserver/src/repositories/resolve.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/repositories/resolve.rs#L80-L81

Added lines #L80 - L81 were not covered by tests
}
}
Expand Down

0 comments on commit 323a3c7

Please sign in to comment.