1
0
Fork 0

Remove optional package loading to simplify pool builder (#11450)

Instead we just directly check if any currently loaded package requires
the package to be loaded optionally.
pull/11453/head
Nils Adermann 2023-05-02 23:59:36 +02:00 committed by GitHub
parent 2928b879d1
commit 595559f68d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 25 deletions

View File

@ -94,11 +94,6 @@ class PoolBuilder
* @phpstan-var array<int, array<string, array<string, PackageInterface>>> * @phpstan-var array<int, array<string, array<string, PackageInterface>>>
*/ */
private $loadedPerRepo = []; private $loadedPerRepo = [];
/**
* @var array[]
* @phpstan-var array<string, bool>
*/
private $optionalPackages = [];
/** /**
* @var BasePackage[] * @var BasePackage[]
*/ */
@ -240,9 +235,8 @@ class PoolBuilder
} }
} }
while ([] !== $this->packagesToLoad || [] !== $this->optionalPackages) { while (!empty($this->packagesToLoad)) {
$this->loadPackagesMarkedForLoading($request, $repositories); $this->loadPackagesMarkedForLoading($request, $repositories);
$this->loadOptionalPackages($request);
} }
if (\count($this->temporaryConstraints) > 0) { if (\count($this->temporaryConstraints) > 0) {
@ -489,8 +483,8 @@ class PoolBuilder
if ($request->getUpdateAllowTransitiveRootDependencies() || !$skippedRootRequires) { if ($request->getUpdateAllowTransitiveRootDependencies() || !$skippedRootRequires) {
$this->unlockPackage($request, $repositories, $replace); $this->unlockPackage($request, $repositories, $replace);
// Mark as optional - if no other package requires it, we don't need to load it // the replaced package only needs to be loaded if something else requires it
$this->markPackageNameForOptionalLoading($replace); $this->markPackageNameForLoadingIfRequired($request, $replace);
} else { } else {
foreach ($skippedRootRequires as $rootRequire) { foreach ($skippedRootRequires as $rootRequire) {
if (!isset($this->updateAllowWarned[$rootRequire])) { if (!isset($this->updateAllowWarned[$rootRequire])) {
@ -662,9 +656,7 @@ class PoolBuilder
foreach ($lockedPackage->getReplaces() as $replace) { foreach ($lockedPackage->getReplaces() as $replace) {
if (isset($requires[$replace->getTarget()], $this->skippedLoad[$replace->getTarget()])) { if (isset($requires[$replace->getTarget()], $this->skippedLoad[$replace->getTarget()])) {
$this->unlockPackage($request, $repositories, $replace->getTarget()); $this->unlockPackage($request, $repositories, $replace->getTarget());
// Do not call markPackageNameForOptionalLoading() here, we know that $lockedPackage is already // this package is in $requires so no need to call markPackageNameForLoadingIfRequired
// part of $this->packages, and we check for $requires[$replace->getTarget()] so we're guaranteed
// to require this package.
$this->markPackageNameForLoading($request, $replace->getTarget(), $replace->getConstraint()); $this->markPackageNameForLoading($request, $replace->getTarget(), $replace->getConstraint());
} }
} }
@ -675,26 +667,15 @@ class PoolBuilder
} }
} }
private function markPackageNameForOptionalLoading(string $name): void private function markPackageNameForLoadingIfRequired(Request $request, string $name): void
{ {
$this->optionalPackages[$name] = true;
}
private function loadOptionalPackages(Request $request): void
{
if ([] === $this->optionalPackages) {
return;
}
foreach ($this->packages as $package) { foreach ($this->packages as $package) {
foreach ($package->getRequires() as $link) { foreach ($package->getRequires() as $link) {
if (isset($this->optionalPackages[$link->getTarget()])) { if ($name === $link->getTarget()) {
$this->markPackageNameForLoading($request, $link->getTarget(), $link->getConstraint()); $this->markPackageNameForLoading($request, $link->getTarget(), $link->getConstraint());
} }
} }
} }
$this->optionalPackages = [];
} }
/** /**