1
0
Fork 0

Avoid storing duplicate packages when loading the same package twice

pull/8850/head
Jordi Boggiano 2020-06-05 17:13:39 +02:00
parent 67a88880ec
commit f2befc46c9
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
3 changed files with 10 additions and 14 deletions

View File

@ -209,17 +209,6 @@ class PoolBuilder
$this->unacceptableFixedPackages = $prePoolCreateEvent->getUnacceptableFixedPackages(); $this->unacceptableFixedPackages = $prePoolCreateEvent->getUnacceptableFixedPackages();
} }
// Filter duplicate packages
// TODO: can we optimize this so that we don't even end up having dupes here?
$presentPackages = array();
foreach ($this->packages as $i => $package) {
if (isset($presentPackages[$package->getUniqueName()])) {
unset($this->packages[$i]);
} else {
$presentPackages[$package->getUniqueName()] = true;
}
}
$pool = new Pool($this->packages, $this->unacceptableFixedPackages); $pool = new Pool($this->packages, $this->unacceptableFixedPackages);
$this->aliasMap = array(); $this->aliasMap = array();
@ -235,7 +224,7 @@ class PoolBuilder
{ {
// Maybe it was already marked before but not loaded yet. In that case // Maybe it was already marked before but not loaded yet. In that case
// we have to extend the constraint (we don't check if they match because // we have to extend the constraint (we don't check if they match because
// MultiConstraint::create() will optimize anyway // MultiConstraint::create() will optimize anyway)
if (isset($this->packagesToLoad[$name]) && !Intervals::isSubsetOf($constraint, $this->packagesToLoad[$name])) { if (isset($this->packagesToLoad[$name]) && !Intervals::isSubsetOf($constraint, $this->packagesToLoad[$name])) {
$constraint = MultiConstraint::create(array($this->packagesToLoad[$name], $constraint), false); $constraint = MultiConstraint::create(array($this->packagesToLoad[$name], $constraint), false);
} }
@ -256,6 +245,13 @@ class PoolBuilder
// yet so we get the required package versions // yet so we get the required package versions
$this->packagesToLoad[$name] = MultiConstraint::create(array($this->loadedPackages[$name], $constraint), false); $this->packagesToLoad[$name] = MultiConstraint::create(array($this->loadedPackages[$name], $constraint), false);
unset($this->loadedPackages[$name]); unset($this->loadedPackages[$name]);
// remove all already-loaded packages matching those to be loaded to avoid duplicates
foreach ($this->packages as $index => $pkg) {
if ($pkg->getName() === $name) {
unset($this->packages[$index]);
}
}
} }
private function loadPackagesMarkedForLoading(Request $request, $repositories) private function loadPackagesMarkedForLoading(Request $request, $repositories)

View File

@ -23,7 +23,7 @@ Tests if version constraint is expanded. If not, dep/dep 3.0.0 would not be load
--EXPECT-- --EXPECT--
[ [
"root/req-1.0.0.0", "root/req-1.0.0.0",
"dep/dep-2.3.4.0",
"dep/dep2-2.3.4.0", "dep/dep2-2.3.4.0",
"dep/dep-2.3.4.0",
"dep/dep-2.3.5.0" "dep/dep-2.3.5.0"
] ]

View File

@ -25,8 +25,8 @@ Tests if version constraint is expanded. If not, dep/dep 3.0.0 would not be load
--EXPECT-- --EXPECT--
[ [
"root/req-1.0.0.0", "root/req-1.0.0.0",
"dep/dep2-2.3.4.0",
"dep/dep-2.3.4.0", "dep/dep-2.3.4.0",
"dep/dep-2.3.5.0", "dep/dep-2.3.5.0",
"dep/dep2-2.3.4.0",
"dep/dep-3.0.0.0" "dep/dep-3.0.0.0"
] ]