Skip to content

Commit

Permalink
Cache source packages when reference/revision is available
Browse files Browse the repository at this point in the history
  • Loading branch information
adduc committed Apr 26, 2017
1 parent 08cf1a3 commit 9438724
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/Indexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,23 @@ public function index(): Promise
$cacheKey = null;
$index = null;
foreach (array_merge($this->composerLock->packages, $this->composerLock->{'packages-dev'}) as $package) {
// Check if package name matches and version is absolute
// Dynamic constraints are not cached, because they can change every time
// Check if package can be cached.
$packageVersion = ltrim($package->version, 'v');
// If package is anchored to a version
if ($package->name === $packageName && strpos($packageVersion, 'dev') === false) {
$packageKey = $packageName . ':' . $packageVersion;
$cacheKey = self::CACHE_VERSION . ':' . $packageKey;
// Check cache
$index = yield $this->cache->get($cacheKey);
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) {
Expand Down

0 comments on commit 9438724

Please sign in to comment.