New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: hashmap based caching #82
Merged
Merged
Changes from all commits
Commits
Show all changes
80 commits
Select commit
Hold shift + click to select a range
7f32245
refactor: naming convention
KSXGitHub 785e878
refactor: remove useless task spawn
KSXGitHub 54b7cc1
feat: panic on invalid UTF-8
KSXGitHub f35fdff
refactor: remove unnecessary copy and allocation
KSXGitHub fe0583d
docs: add a TODO
KSXGitHub 3b600d9
refactor: remove node_modules_path
KSXGitHub 5301577
feat: hashmap caching communication
KSXGitHub cbfe18c
feat: log cache hit
KSXGitHub e83c4c0
chore: merge from main
KSXGitHub ed708b1
feat: use tracing library
KSXGitHub 0fe3e95
feat: propagate archive error
KSXGitHub f7b32cd
docs: change the TODO
KSXGitHub 7bcaf06
refactor: rename cache state
KSXGitHub 4d1b724
feat: remove unused function
KSXGitHub 2103470
docs: ask a question
KSXGitHub 85dc278
feat: import on cache hit
KSXGitHub ca7de84
feat: log saved_path
KSXGitHub d06fd00
feat: log cache miss
KSXGitHub a23fc50
feat: change tracing level
KSXGitHub 8c4c276
style: consistent string substitution style
KSXGitHub 21a2f89
docs: add a TODO
KSXGitHub 6bd33e9
docs: add a TODO
KSXGitHub 10b8be0
docs: remove poor comment
KSXGitHub 242c189
docs: add a TODO
KSXGitHub a602dfa
docs: add a TODO
KSXGitHub cfbac93
feat: fix tracing
KSXGitHub 77adf35
feat: set_panic_hook
KSXGitHub 73d8a9c
refactor: remove unnecessary error variant
KSXGitHub a70b0ee
refactor: remove unnecessary error variant
KSXGitHub 3b17d25
refactor: rename InProcess to InProgress
KSXGitHub 608c2df
refactor: remove anti-pattern generics
KSXGitHub 7c065e8
refactor: remove anti-pattern generics
KSXGitHub 2ebb0fb
feat: re-add spawn
KSXGitHub f03439a
docs: add a TODO
KSXGitHub 002efb0
feat: propagate more error
KSXGitHub 6557a7b
feat: propagate more error
KSXGitHub 21280ed
refactor: remove some intermediate variables
KSXGitHub 1bee692
refactor: broadcast is simpler
KSXGitHub b5470ea
refactor: mpsc is even simpler
KSXGitHub 4fb716a
docs: add a TODO
KSXGitHub 889149a
feat: attach culprit information to error
KSXGitHub ea40c87
chore: merge from main
KSXGitHub bddeaa7
feat: attach more information to error
KSXGitHub a59af39
refactor: replace a PathBuf with &Path
KSXGitHub 9399c70
feat: more resistance to race conditions
KSXGitHub 7bc4943
refactor: change the misleading names
KSXGitHub 2ea6e34
refactor: reduce indentation
KSXGitHub a2c19c6
fix: the tarball bug
KSXGitHub 9cfa9a1
chore: merge from main
KSXGitHub 74f9dd3
feat: revert previous change
KSXGitHub aa3dfa2
feat: switch to RwLock
KSXGitHub e68e3ea
docs: add a TODO
KSXGitHub 480bbba
feat: avoid filling the screen with numbers
KSXGitHub 34b322e
feat: trace install
KSXGitHub a24137b
feat: trace import
KSXGitHub bf8cb58
feat: move parsing of integrity out
KSXGitHub a339c65
feat: correct error message and diagnostic
KSXGitHub 898dee6
feat: propagate parse_integrity_error
KSXGitHub b846256
feat: remove unnecessary clone
KSXGitHub 2c1eed2
feat: url based caching
KSXGitHub 73388b3
feat: full parallelization
KSXGitHub 8c7db75
feat: skip logging cache
KSXGitHub c8887ad
feat: log cache.len()
KSXGitHub 479e7e3
feat: log beginning and end of sets and subsets
KSXGitHub fe32b99
feat: drop lock and sleep
KSXGitHub 9b24ea1
docs: millis
KSXGitHub 80346b6
chore: remove an unused dependency
KSXGitHub 3c380a5
refactor: change var name
KSXGitHub 3c3f4b8
refactor: only compute `save_path` when necessary
KSXGitHub b921350
docs: remove a TODO
KSXGitHub fc3e7d0
style: fix string interpolation style
KSXGitHub 104fbcd
docs: move a TODO
KSXGitHub baa9b82
docs: clarify
KSXGitHub c736d86
feat: change log message
KSXGitHub d5eb906
fix: log message grammar
KSXGitHub 90eb4d5
refactor: remove box
KSXGitHub 42422bd
docs: remove the question
KSXGitHub b76f3a4
feat: reduce panic by using OsString
KSXGitHub 663dd8d
feat: replace `sleep` with `yield_now`
KSXGitHub c386708
refactor: forgot to reuse `url`
KSXGitHub File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
use crate::package::find_package_version_from_registry; | ||
use crate::package_manager::{PackageManager, PackageManagerError}; | ||
use async_recursion::async_recursion; | ||
use clap::Parser; | ||
use futures_util::future; | ||
use pacquet_diagnostics::tracing; | ||
use pacquet_package_json::DependencyGroup; | ||
use pacquet_registry::PackageVersion; | ||
use std::collections::VecDeque; | ||
use pipe_trait::Pipe; | ||
|
||
#[derive(Parser, Debug)] | ||
pub struct InstallCommandArgs { | ||
|
@@ -40,49 +42,60 @@ | |
} | ||
|
||
impl PackageManager { | ||
/// Install dependencies of a dependency. | ||
/// | ||
/// This function is used by [`PackageManager::install`]. | ||
#[async_recursion] | ||
async fn install_dependencies(&self, package: &PackageVersion) { | ||
let node_modules_path = | ||
self.config.virtual_store_dir.join(package.to_store_name()).join("node_modules"); | ||
|
||
tracing::info!(target: "pacquet::install", node_modules = ?node_modules_path, "Start subset"); | ||
|
||
package | ||
.dependencies(self.config.auto_install_peers) | ||
.map(|(name, version)| async { | ||
let dependency = find_package_version_from_registry( | ||
&self.tarball_cache, | ||
&self.config, | ||
&self.http_client, | ||
name, | ||
version, | ||
&node_modules_path, | ||
) | ||
.await | ||
.unwrap(); | ||
self.install_dependencies(&dependency).await; | ||
}) | ||
.pipe(future::join_all) | ||
.await; | ||
|
||
tracing::info!(target: "pacquet::install", node_modules = ?node_modules_path, "Complete subset"); | ||
} | ||
|
||
/// Jobs of the `install` command. | ||
pub async fn install(&self, args: &InstallCommandArgs) -> Result<(), PackageManagerError> { | ||
let config = &self.config; | ||
let path = &self.config.modules_dir; | ||
let http_client = &self.http_client; | ||
let mut queue: VecDeque<Vec<PackageVersion>> = VecDeque::new(); | ||
tracing::info!(target: "pacquet::install", "Start all"); | ||
|
||
let direct_dependency_handles = self | ||
.package_json | ||
self.package_json | ||
.dependencies(args.dependency_groups()) | ||
.map(|(name, version)| async move { | ||
find_package_version_from_registry(config, http_client, name, version, path) | ||
.await | ||
.unwrap() | ||
}); | ||
|
||
queue.push_front(future::join_all(direct_dependency_handles).await); | ||
|
||
while let Some(dependencies) = queue.pop_front() { | ||
for dependency in dependencies { | ||
let node_modules_path = self | ||
.config | ||
.virtual_store_dir | ||
.join(dependency.to_store_name()) | ||
.join("node_modules"); | ||
|
||
let handles = dependency.dependencies(self.config.auto_install_peers).map( | ||
|(name, version)| async { | ||
find_package_version_from_registry( | ||
config, | ||
http_client, | ||
name, | ||
version, | ||
&node_modules_path, | ||
) | ||
.await | ||
.unwrap() | ||
}, | ||
); | ||
|
||
queue.push_back(future::join_all(handles).await); | ||
} | ||
} | ||
|
||
let dependency = find_package_version_from_registry( | ||
&self.tarball_cache, | ||
&self.config, | ||
&self.http_client, | ||
name, | ||
version, | ||
&self.config.modules_dir, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are already passing self.config to this function. We dont need this do we? |
||
) | ||
.await | ||
.unwrap(); | ||
self.install_dependencies(&dependency).await; | ||
}) | ||
.pipe(future::join_all) | ||
.await; | ||
|
||
tracing::info!(target: "pacquet::install", "Complete all"); | ||
Ok(()) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we using async-recursion? I couldn't find any reference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pacquet/crates/cli/src/commands/install.rs
Line 48 in 9c94551