1
0
Fork 0

Merge pull request #8874 from Seldaek/cache_successes

Cache successful requests to make sure subsequent loadPackages calls do not do the same requests for nothing
pull/8880/head
Nils Adermann 2020-05-04 22:16:00 +02:00 committed by GitHub
commit a9ae54d1bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 0 deletions

View File

@ -70,6 +70,14 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
private $hasPartialPackages; private $hasPartialPackages;
private $partialPackagesByName; private $partialPackagesByName;
/**
* TODO v3 should make this private once we can drop PHP 5.3 support
* @private
* @var array list of package names which are fresh and can be loaded from the cache directly in case loadPackage is called several times
* useful for v2 metadata repositories with lazy providers
*/
public $freshMetadataUrls = array();
/** /**
* TODO v3 should make this private once we can drop PHP 5.3 support * TODO v3 should make this private once we can drop PHP 5.3 support
* @private * @private
@ -1150,6 +1158,11 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
return new Promise(function ($resolve, $reject) { $resolve(array('packages' => array())); }); return new Promise(function ($resolve, $reject) { $resolve(array('packages' => array())); });
} }
if (isset($this->freshMetadataUrls[$filename]) && $lastModifiedTime) {
// make it look like we got a 304 response
return new Promise(function ($resolve, $reject) { $resolve(true); });
}
$httpDownloader = $this->httpDownloader; $httpDownloader = $this->httpDownloader;
if ($this->eventDispatcher) { if ($this->eventDispatcher) {
$preFileDownloadEvent = new PreFileDownloadEvent(PluginEvents::PRE_FILE_DOWNLOAD, $this->httpDownloader, $filename); $preFileDownloadEvent = new PreFileDownloadEvent(PluginEvents::PRE_FILE_DOWNLOAD, $this->httpDownloader, $filename);
@ -1173,6 +1186,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
$json = $response->getBody(); $json = $response->getBody();
if ($json === '' && $response->getStatusCode() === 304) { if ($json === '' && $response->getStatusCode() === 304) {
$repo->freshMetadataUrls[$filename] = true;
return true; return true;
} }
@ -1186,6 +1200,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
$json = JsonFile::encode($data, JsonFile::JSON_UNESCAPED_SLASHES | JsonFile::JSON_UNESCAPED_UNICODE); $json = JsonFile::encode($data, JsonFile::JSON_UNESCAPED_SLASHES | JsonFile::JSON_UNESCAPED_UNICODE);
} }
$cache->write($cacheKey, $json); $cache->write($cacheKey, $json);
$repo->freshMetadataUrls[$filename] = true;
return $data; return $data;
}; };