Skip to content

Commit

Permalink
Merge pull request #9177 from simonberger/reduce-requests
Browse files Browse the repository at this point in the history
Re-Fetch cached packages only once in a run
  • Loading branch information
Seldaek committed Sep 7, 2020
2 parents 943c7a6 + cb3c71a commit 8694077
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/Composer/Repository/ComposerRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
*/
class ComposerRepository extends ArrayRepository implements ConfigurableRepositoryInterface
{
private $config;
private $repoConfig;
private $options;
private $url;
Expand Down Expand Up @@ -102,7 +101,7 @@ public function __construct(array $repoConfig, IOInterface $io, Config $config,
}
$repoConfig['url'] = rtrim($repoConfig['url'], '/');

if ('https?' === substr($repoConfig['url'], 0, 6)) {
if (strpos($repoConfig['url'], 'https?') === 0) {
$repoConfig['url'] = (extension_loaded('openssl') ? 'https' : 'http') . substr($repoConfig['url'], 6);
}

Expand All @@ -118,7 +117,6 @@ public function __construct(array $repoConfig, IOInterface $io, Config $config,
$this->allowSslDowngrade = true;
}

$this->config = $config;
$this->options = $repoConfig['options'];
$this->url = $repoConfig['url'];

Expand Down Expand Up @@ -570,13 +568,12 @@ private function whatProvides($name, array $acceptableStabilities = null, array
} elseif ($useLastModifiedCheck) {
if ($contents = $this->cache->read($cacheKey)) {
$contents = json_decode($contents, true);
if (isset($contents['last-modified'])) {
// we already loaded some packages from this file, so assume it is fresh and avoid fetching it again
if (isset($alreadyLoaded[$name])) {
$packages = $contents;
} elseif (isset($contents['last-modified'])) {
$response = $this->fetchFileIfLastModified($url, $cacheKey, $contents['last-modified']);
if (true === $response) {
$packages = $contents;
} elseif ($response) {
$packages = $response;
}
$packages = true === $response ? $contents : $response;
}
}
}
Expand Down

0 comments on commit 8694077

Please sign in to comment.