Skip to content

Commit 9438724

Browse files
committed
Cache source packages when reference/revision is available
Fixes #366
1 parent 08cf1a3 commit 9438724

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/Indexer.php

+10-2
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,23 @@ public function index(): Promise
149149
$cacheKey = null;
150150
$index = null;
151151
foreach (array_merge($this->composerLock->packages, $this->composerLock->{'packages-dev'}) as $package) {
152-
// Check if package name matches and version is absolute
153-
// Dynamic constraints are not cached, because they can change every time
152+
// Check if package can be cached.
154153
$packageVersion = ltrim($package->version, 'v');
154+
// If package is anchored to a version
155155
if ($package->name === $packageName && strpos($packageVersion, 'dev') === false) {
156156
$packageKey = $packageName . ':' . $packageVersion;
157157
$cacheKey = self::CACHE_VERSION . ':' . $packageKey;
158158
// Check cache
159159
$index = yield $this->cache->get($cacheKey);
160160
break;
161+
162+
// If package is checked out
163+
} elseif ($package->name === $packageName && isset($package->source->reference)) {
164+
$packageKey = $packageName . ':' . $package->source->reference;
165+
$cacheKey = self::CACHE_VERSION . ':' . $packageKey;
166+
// Check cache
167+
$index = yield $this->cache->get($cacheKey);
168+
break;
161169
}
162170
}
163171
if ($index !== null) {

0 commit comments

Comments
 (0)