Skip to content

Commit

Permalink
Added some quick'n'dirty cache invalidation to "wasmer publish"
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael-F-Bryan committed Jun 16, 2023
1 parent 2d22557 commit e1bad73
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
29 changes: 28 additions & 1 deletion lib/cli/src/commands/publish.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use anyhow::Context;
use clap::Parser;
use wasmer_registry::WasmerConfig;
use wasmer_wasix::runtime::resolver::WapmSource;

/// Publish a package to the package registry.
#[derive(Debug, Parser)]
Expand Down Expand Up @@ -44,7 +47,16 @@ impl Publish {
no_validate: self.no_validate,
package_path: self.package_path.clone(),
};
publish.execute().map_err(on_error)
publish.execute().map_err(on_error)?;

if let Err(e) = invalidate_graphql_query_cache() {
tracing::warn!(
error = &*e,
"Unable to invalidate the cache used for package version queries",
);
}

Ok(())
}
}

Expand All @@ -54,3 +66,18 @@ fn on_error(e: anyhow::Error) -> anyhow::Error {

e
}

// HACK: We want to invalidate the cache used for GraphQL queries so
// the current user sees the results of publishing immediately. There
// are cleaner ways to achieve this, but for now we're just going to
// clear out the whole GraphQL query cache.
// See https://github.com/wasmerio/wasmer/pull/3983 for more
fn invalidate_graphql_query_cache() -> Result<(), anyhow::Error> {
let wasmer_dir = WasmerConfig::get_wasmer_dir()
.map_err(anyhow::Error::msg)
.context("Unable to determine the wasmer dir")?;

let cache_dir = WapmSource::invalidate_local_cache(wasmer_dir)?;

Ok(())
}
14 changes: 14 additions & 0 deletions lib/wasix/src/runtime/resolver/wapm_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ impl WapmSource {
}
}

/// Clean the local cache.
///
/// This is a workaround used primarily when publishing and will probably
/// be removed in the future.
pub fn invalidate_local_cache(wasmer_dir: impl AsRef<Path>) -> Result<(), Error> {
let cache_dir = WapmSource::default_cache_dir(wasmer_dir);

std::fs::remove_dir_all(cache_dir).with_context(|| {
format!("Unable to delete the \"{}\" directory", cache_dir.display())
})?;

Ok(())
}

async fn lookup_package(&self, package_name: &str) -> Result<WapmWebQuery, Error> {
if let Some(cache) = &self.cache {
match cache.lookup_cached_query(package_name) {
Expand Down

0 comments on commit e1bad73

Please sign in to comment.