Skip to content
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

DX: Cache optimisation #7985

Merged
merged 6 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Cache/CacheManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ interface CacheManagerInterface
public function needFixing(string $file, string $fileContent): bool;

public function setFile(string $file, string $fileContent): void;

public function setFileHash(string $file, string $hash): void;
}
7 changes: 5 additions & 2 deletions src/Cache/FileCacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,12 @@ public function needFixing(string $file, string $fileContent): bool

public function setFile(string $file, string $fileContent): void
{
$file = $this->cacheDirectory->getRelativePathTo($file);
$this->setFileHash($file, $this->calcHash($fileContent));
}

$hash = $this->calcHash($fileContent);
public function setFileHash(string $file, string $hash): void
{
$file = $this->cacheDirectory->getRelativePathTo($file);

if ($this->isDryRun && $this->cache->has($file) && $this->cache->get($file) !== $hash) {
$this->cache->clear($file);
Expand Down
3 changes: 3 additions & 0 deletions src/Cache/NullCacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

/**
* @author Andreas Möller <am@localheinz.com>
* @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
*
* @internal
*/
Expand All @@ -27,4 +28,6 @@ public function needFixing(string $file, string $fileContent): bool
}

public function setFile(string $file, string $fileContent): void {}

public function setFileHash(string $file, string $hash): void {}
}
4 changes: 2 additions & 2 deletions src/Runner/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@
$tokens = Tokens::fromCode($old);
$oldHash = $tokens->getCodeHash();

$newHash = $oldHash;
$new = $old;
$newHash = $oldHash;

$appliedFixers = [];

Expand Down Expand Up @@ -266,7 +266,7 @@
}
}

$this->cacheManager->setFile($name, $new);
$this->cacheManager->setFileHash($name, $newHash);

Check warning on line 269 in src/Runner/Runner.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 mutation tests

Escaped Mutant for Mutator "MethodCallRemoval": --- Original +++ New @@ @@ } } } - $this->cacheManager->setFileHash($name, $newHash); + $this->dispatchEvent(FixerFileProcessedEvent::NAME, new FixerFileProcessedEvent(null !== $fixInfo ? FixerFileProcessedEvent::STATUS_FIXED : FixerFileProcessedEvent::STATUS_NO_CHANGES)); return $fixInfo; }
Copy link
Member Author

@keradus keradus May 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the optimization part, when we already had newHash calculated (line 158 and 200) and there is no need to re-calculate it


$this->dispatchEvent(
FixerFileProcessedEvent::NAME,
Expand Down
5 changes: 5 additions & 0 deletions tests/Runner/FileFilterIteratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@ public function setFile(string $file, string $fileContent): void
{
throw new \LogicException('Not implemented.');
}

public function setFileHash(string $file, string $hash): void
{
throw new \LogicException('Not implemented.');
}
};
}
}