1
0
Fork 0

Speed up fund command fetching of latest data and make sure it uses default branch info

pull/9026/head
Jordi Boggiano 2020-06-25 08:57:18 +02:00
parent 6f9b39180c
commit a133e694d0
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
1 changed files with 28 additions and 3 deletions

View File

@ -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);
}