1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-25 16:49:18 -05:00

perf: disable fetching graph cache info except for deno info (#17698)

This commit is contained in:
David Sherret 2023-02-08 19:45:04 -05:00 committed by GitHub
parent ef9b66950f
commit 8b0a612e30
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

12
cli/cache/mod.rs vendored
View file

@ -45,6 +45,7 @@ pub struct FetchCacher {
dynamic_permissions: PermissionsContainer,
file_fetcher: Arc<FileFetcher>,
root_permissions: PermissionsContainer,
cache_info_enabled: bool,
}
impl FetchCacher {
@ -59,12 +60,23 @@ impl FetchCacher {
dynamic_permissions,
file_fetcher,
root_permissions,
cache_info_enabled: false,
}
}
/// The cache information takes a bit of time to fetch and it's
/// not always necessary. It should only be enabled for deno info.
pub fn enable_loading_cache_info(&mut self) {
self.cache_info_enabled = true;
}
}
impl Loader for FetchCacher {
fn get_cache_info(&self, specifier: &ModuleSpecifier) -> Option<CacheInfo> {
if !self.cache_info_enabled {
return None;
}
if matches!(specifier.scheme(), "npm" | "node") {
return None;
}

View file

@ -33,7 +33,11 @@ pub async fn info(flags: Flags, info_flags: InfoFlags) -> Result<(), AnyError> {
let ps = ProcState::build(flags).await?;
if let Some(specifier) = info_flags.file {
let specifier = resolve_url_or_path(&specifier)?;
let graph = ps.create_graph(vec![specifier]).await?;
let mut loader = ps.create_graph_loader();
loader.enable_loading_cache_info(); // for displaying the cache information
let graph = ps
.create_graph_with_loader(vec![specifier], &mut loader)
.await?;
if info_flags.json {
let mut json_graph = json!(graph);