Skip to content

Conversation

@samsonasik
Copy link
Member

@samsonasik samsonasik commented Jul 6, 2025

Ref #7045 (comment)

Closes #7045
Closes Closes rectorphp/rector#9231

@samsonasik samsonasik force-pushed the save-kaizen-applied-rules-to-cache branch from 77e8380 to 72d91ac Compare July 6, 2025 16:49
register directory

register directory
@samsonasik samsonasik force-pushed the save-kaizen-applied-rules-to-cache branch from 72d91ac to b53b595 Compare July 6, 2025 16:51
@samsonasik
Copy link
Member Author

I've added e2e test for it with maxNumberOfProcess: 2, jobSize: 1 on 4 files for it b53b595 with kaizen 1, it seems cause error on CI (applied 2 rules), while working on locally.

Ref https://github.com/rectorphp/rector-src/actions/runs/16101183170/job/45430530419?pr=7046

It can possibly due to on CI, the cache overlapped call

@samsonasik
Copy link
Member Author

I got it, it seems due to default CI use MemoryCacheStorage, I updated to use FileCacheStorage on e2e config and it seems working ok now 👍 https://github.com/rectorphp/rector-src/actions/runs/16101393029/job/45431005381?pr=7046

@samsonasik
Copy link
Member Author

All checks have passed 🎉 @gharlan @TomasVotruba it is ready for review.

@samsonasik samsonasik requested a review from TomasVotruba July 6, 2025 17:19
@samsonasik
Copy link
Member Author

@TomasVotruba let's merge to have faster feedback to test ;)

@samsonasik samsonasik merged commit 1233b63 into main Jul 7, 2025
47 checks passed
@samsonasik samsonasik deleted the save-kaizen-applied-rules-to-cache branch July 7, 2025 17:11
$cachedValue = $this->loadRules();

$appliedRectorClasses = array_unique(array_merge($cachedValue, [$rectorClass]));
$this->cache->save($this->getCacheKey(), CacheKey::KAIZEN_RULES, $appliedRectorClasses);
Copy link
Member

Choose a reason for hiding this comment

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

Nice trick 👏 🥳

@gharlan
Copy link

gharlan commented Jul 7, 2025

Thanks! I tried it in my project (via rector/rector dev-main, which is already updated: rectorphp/rector@c243796).

The first run of rector process --kaizen=1 now works correctly 👍 Only one rule is applied. In my case that rule changed 16 files of 747.

$ rector process --kaizen=1
[EXPERIMENTAL] Running Kaizen mode. Only first 1 rule will be applied

 747/747 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%16 files with change

[...]

 [OK] 16 files have been changed by Rector

But the next run only "looks" at the 16 changed files:

$ rector process --kaizen=1
[EXPERIMENTAL] Running Kaizen mode. Only first 1 rule will be applied

 16/16 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

 [OK] Rector is done!

@samsonasik
Copy link
Member Author

@gharlan thank you for verify, that's expected, or we may need to force clear cache when --kaizen used.

The combination with --clear-cache is needed for now, and we can discuss about whether cache need to be cleared when kaizen is used.

Please create new feature request for that so this can be discussed further.

@samsonasik
Copy link
Member Author

nvm, I created PR for that :)

@github-actions
Copy link
Contributor

github-actions bot commented Dec 7, 2025

This pull request has been automatically locked because it has been closed for 150 days. Please open a new PR if you want to continue the work.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 7, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--kaizen not working when using withParallel()

5 participants