Skip to content

Commit 60b9ed6

Browse files
committed
Avoid lookups to repo if possible
1 parent ffaf55f commit 60b9ed6

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

src/lockfile.rs

+4
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ impl Source {
8989
matches!(self, Source::Git { .. } | Source::Url { .. })
9090
}
9191

92+
pub fn is_repo(&self) -> bool {
93+
matches!(self, Source::Repository { .. })
94+
}
95+
9296
/// The key to use in the cache: URL for a package repository, git URL for a git repository
9397
/// and for local the actual path
9498
pub fn source_path(&self) -> &str {

src/resolver/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,12 @@ impl<'d> Resolver<'d> {
503503
None
504504
| Some(ConfigDependency::Detailed { .. })
505505
| Some(ConfigDependency::Simple(_)) => {
506+
// If we already have something that will satisfy the dependency, no need
507+
// to look it up again
508+
if item.version_requirement.is_none() && result.found_in_repo(&item.name) {
509+
continue;
510+
}
511+
506512
if let Some((resolved_dep, items)) = self.repositories_lookup(&item, cache) {
507513
result.add_found(resolved_dep);
508514
queue.extend(items);

src/resolver/result.rs

+9
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ impl<'d> Resolution<'d> {
3232
self.found.push(dep);
3333
}
3434

35+
/// If we already found something matching, we skip trying to get it.
36+
/// This is only called when we would look up a repo for a package without a version requirement
37+
pub(crate) fn found_in_repo(&self, name: &str) -> bool {
38+
self.found
39+
.iter()
40+
.find(|d| d.source.is_repo() && d.name == name)
41+
.is_some()
42+
}
43+
3544
pub fn finalize(&mut self) {
3645
let mut solver = DependencySolver::default();
3746
for package in &self.found {

0 commit comments

Comments
 (0)