-
-
Notifications
You must be signed in to change notification settings - Fork 366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify ChangedFilesDetector #6662
Conversation
@@ -98,11 +95,6 @@ private function getFilePathCacheKey(string $filePath): string | |||
return $this->fileHasher->hash($this->resolvePath($filePath)); | |||
} | |||
|
|||
private function hashFile(string $filePath): string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this method did the same thing as getFilePathCacheKey
, therefore just drop it and save unnecessary re-hash'ing of files, we already hashed before
@@ -53,8 +51,7 @@ public function hasFileChanged(string $filePath): bool | |||
$cachedValue = $this->cache->load($fileInfoCacheKey, CacheKey::FILE_HASH_KEY); | |||
|
|||
if ($cachedValue !== null) { | |||
$currentFileHash = $this->hashFile($filePath); | |||
return $currentFileHash !== $cachedValue; | |||
return $fileInfoCacheKey !== $cachedValue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fileInfoCacheKey is cache key, while file hash is hashed of file, seems different
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it has the same content though - see the impl is equivalent
rector-src/src/Caching/Detector/ChangedFilesDetector.php
Lines 96 to 104 in c59c83a
private function getFilePathCacheKey(string $filePath): string | |
{ | |
return $this->fileHasher->hash($this->resolvePath($filePath)); | |
} | |
private function hashFile(string $filePath): string | |
{ | |
return $this->fileHasher->hashFiles([$this->resolvePath($filePath)]); | |
} |
both just contain the hash of the file-path-content
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- the
hash()
method usinghash()
function.
rector-src/src/Util/FileHasher.php
Lines 17 to 19 in c59c83a
public function hash(string $string): string | |
{ | |
return hash($this->getAlgo(), $string); |
- the
hashFiles()
method usinghash_file()
function.
rector-src/src/Util/FileHasher.php
Lines 27 to 32 in c59c83a
public function hashFiles(array $files): string | |
{ | |
$configHash = ''; | |
$algo = $this->getAlgo(); | |
foreach ($files as $file) { | |
$hash = hash_file($algo, $file); |
so the usage seems different ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested that hash()
have different result vs hash_file()
, see below:
➜ rector-src git:(main) php -a
Interactive shell
php > echo hash('xxh128', 'vendor/autoload.php');
ed4ee810129ade2015db3142c912be83
php > echo hash_file('xxh128', 'vendor/autoload.php');
d69f0ce7c725ec2c59342d08f047a9ad
so the change seems different.
I am closing this as |
remove unnecessary/redundant IO operations.
drive-by cleanup while looking into rectorphp/rector#8966