Skip to content

Commit

Permalink
Fix vimeo#4464 - bust cache when Psalm’s version changes, not just co…
Browse files Browse the repository at this point in the history
…mposer’s
  • Loading branch information
muglug authored and danog committed Jan 29, 2021
1 parent afc38b8 commit 9d35e3c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/Psalm/Internal/Analyzer/ProjectAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ public function check(string $base_dir, bool $is_diff = false): void

if ($this->project_cache_provider && $this->parser_cache_provider) {
$removed_parser_files = $this->parser_cache_provider->deleteOldParserCaches(
$is_diff ? $this->project_cache_provider->getLastRun() : $start_checks
$is_diff ? $this->project_cache_provider->getLastRun(\PSALM_VERSION) : $start_checks
);

if ($removed_parser_files) {
Expand Down Expand Up @@ -1069,7 +1069,7 @@ protected function getDiffFilesInDir(string $dir_name, Config $config): array

$diff_files = [];

$last_run = $this->project_cache_provider->getLastRun();
$last_run = $this->project_cache_provider->getLastRun(\PSALM_VERSION);

$file_paths = $this->file_provider->getFilesInDir($dir_name, $file_extensions);

Expand Down
12 changes: 8 additions & 4 deletions src/Psalm/Internal/Provider/ProjectCacheProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function canDiffFiles(): bool
return $cache_directory && file_exists($cache_directory . DIRECTORY_SEPARATOR . self::GOOD_RUN_NAME);
}

public function processSuccessfulRun(float $start_time): void
public function processSuccessfulRun(float $start_time, string $psalm_version): void
{
$cache_directory = Config::getInstance()->getCacheDirectory();

Expand All @@ -50,16 +50,20 @@ public function processSuccessfulRun(float $start_time): void

$run_cache_location = $cache_directory . DIRECTORY_SEPARATOR . self::GOOD_RUN_NAME;

file_put_contents($run_cache_location, $psalm_version);

\touch($run_cache_location, (int)$start_time);
}

public function getLastRun(): int
public function getLastRun(string $psalm_version): int
{
if ($this->last_run === null) {
$cache_directory = Config::getInstance()->getCacheDirectory();

if (file_exists($cache_directory . DIRECTORY_SEPARATOR . self::GOOD_RUN_NAME)) {
$this->last_run = \filemtime($cache_directory . DIRECTORY_SEPARATOR . self::GOOD_RUN_NAME);
$run_cache_location = $cache_directory . DIRECTORY_SEPARATOR . self::GOOD_RUN_NAME;

if (file_exists($run_cache_location) && file_get_contents($run_cache_location) === $psalm_version) {
$this->last_run = \filemtime($run_cache_location);
} else {
$this->last_run = 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/IssueBuffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ function (IssueData $d1, IssueData $d2) : int {
$codebase->file_reference_provider->removeDeletedFilesFromReferences();

if ($project_analyzer->project_cache_provider) {
$project_analyzer->project_cache_provider->processSuccessfulRun($start_time);
$project_analyzer->project_cache_provider->processSuccessfulRun($start_time, \PSALM_VERSION);
}

if ($codebase->statements_provider->parser_cache_provider) {
Expand Down
4 changes: 2 additions & 2 deletions tests/Internal/Provider/ProjectCacheProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ public function __construct()
{
}

public function getLastRun(): int
public function getLastRun(string $psalm_version): int
{
return $this->last_run;
}

public function processSuccessfulRun(float $start_time): void
public function processSuccessfulRun(float $start_time, string $psalm_version): void
{
$this->last_run = (int) $start_time;
}
Expand Down

0 comments on commit 9d35e3c

Please sign in to comment.