From 9438724f28b387484283f18deb1b73ca44d17c9a Mon Sep 17 00:00:00 2001 From: John S Long Date: Tue, 25 Apr 2017 22:48:06 -0500 Subject: [PATCH] Cache source packages when reference/revision is available Fixes #366 --- src/Indexer.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Indexer.php b/src/Indexer.php index 34ad618f..00043cbd 100644 --- a/src/Indexer.php +++ b/src/Indexer.php @@ -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) {