From a133e694d06916672d4620b6741eb4d7348598cd Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 25 Jun 2020 08:57:18 +0200 Subject: [PATCH] Speed up fund command fetching of latest data and make sure it uses default branch info --- src/Composer/Command/FundCommand.php | 31 +++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/Composer/Command/FundCommand.php b/src/Composer/Command/FundCommand.php index eb60ec577..a5c4dfc02 100644 --- a/src/Composer/Command/FundCommand.php +++ b/src/Composer/Command/FundCommand.php @@ -14,6 +14,8 @@ namespace Composer\Command; use Composer\Package\CompletePackageInterface; use Composer\Package\AliasPackage; +use Composer\Package\BasePackage; +use Composer\Semver\Constraint\MatchAllConstraint; use Composer\Repository\CompositeRepository; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -39,15 +41,38 @@ class FundCommand extends BaseCommand $repo = $composer->getRepositoryManager()->getLocalRepository(); $remoteRepos = new CompositeRepository($composer->getRepositoryManager()->getRepositories()); $fundings = array(); + + $packagesToLoad = array(); foreach ($repo->getPackages() as $package) { if ($package instanceof AliasPackage) { continue; } - $latest = $remoteRepos->findPackage($package->getName(), 'dev-master'); - if ($latest instanceof CompletePackageInterface && $latest->getFunding()) { - $fundings = $this->insertFundingData($fundings, $latest); + $packagesToLoad[$package->getName()] = new MatchAllConstraint(); + } + + // load all packages dev versions in parallel + $result = $remoteRepos->loadPackages($packagesToLoad, array('dev' => BasePackage::STABILITY_DEV), array()); + + // collect funding data from default branches + foreach ($result['packages'] as $pkg) { + if ( + !$pkg instanceof AliasPackage + && $pkg instanceof CompletePackageInterface + && $pkg->isDefaultBranch() + && $pkg->getFunding() + && isset($packagesToLoad[$pkg->getName()]) + ) { + $fundings = $this->insertFundingData($fundings, $pkg); + unset($packagesToLoad[$package->getName()]); + } + } + + // collect funding from installed packages if none was found in the default branch above + foreach ($repo->getPackages() as $package) { + if ($package instanceof AliasPackage || !isset($packagesToLoad[$package->getName()])) { continue; } + if ($package instanceof CompletePackageInterface && $package->getFunding()) { $fundings = $this->insertFundingData($fundings, $package); }