Skip to content

Commit

Permalink
Prevent unnecessary IO in ChangedFilesDetector (#3650)
Browse files Browse the repository at this point in the history
* Prevent unnecessary IO in ChangedFilesDetector

* Docs
  • Loading branch information
staabm committed Apr 22, 2023
1 parent d777f36 commit 81e7980
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/Caching/Detector/ChangedFilesDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,16 @@ public function addFileWithDependencies(string $filePath, array $dependentFiles)

public function hasFileChanged(string $filePath): bool
{
$currentFileHash = $this->hashFile($filePath);
$fileInfoCacheKey = $this->getFilePathCacheKey($filePath);

$cachedValue = $this->cache->load($fileInfoCacheKey, CacheKey::FILE_HASH_KEY);
return $currentFileHash !== $cachedValue;

if ($cachedValue !== null) {
$currentFileHash = $this->hashFile($filePath);
return $currentFileHash !== $cachedValue;
}

// we don't have a value to compare against. Be defensive and assume its changed
return true;
}

public function invalidateFile(string $filePath): void
Expand Down

0 comments on commit 81e7980

Please sign in to comment.