1
0
Fork 0

Cache source packages when reference/revision is available

Fixes #366
pull/367/head
John S Long 2017-04-25 22:48:06 -05:00
parent 08cf1a3fd7
commit 9438724f28
1 changed files with 10 additions and 2 deletions

View File

@ -149,15 +149,23 @@ class Indexer
$cacheKey = null; $cacheKey = null;
$index = null; $index = null;
foreach (array_merge($this->composerLock->packages, $this->composerLock->{'packages-dev'}) as $package) { foreach (array_merge($this->composerLock->packages, $this->composerLock->{'packages-dev'}) as $package) {
// Check if package name matches and version is absolute // Check if package can be cached.
// Dynamic constraints are not cached, because they can change every time
$packageVersion = ltrim($package->version, 'v'); $packageVersion = ltrim($package->version, 'v');
// If package is anchored to a version
if ($package->name === $packageName && strpos($packageVersion, 'dev') === false) { if ($package->name === $packageName && strpos($packageVersion, 'dev') === false) {
$packageKey = $packageName . ':' . $packageVersion; $packageKey = $packageName . ':' . $packageVersion;
$cacheKey = self::CACHE_VERSION . ':' . $packageKey; $cacheKey = self::CACHE_VERSION . ':' . $packageKey;
// Check cache // Check cache
$index = yield $this->cache->get($cacheKey); $index = yield $this->cache->get($cacheKey);
break; break;
// If package is checked out
} elseif ($package->name === $packageName && isset($package->source->reference)) {
$packageKey = $packageName . ':' . $package->source->reference;
$cacheKey = self::CACHE_VERSION . ':' . $packageKey;
// Check cache
$index = yield $this->cache->get($cacheKey);
break;
} }
} }
if ($index !== null) { if ($index !== null) {