Skip to content

[Cache] Prevent unnecessary file IO #50095

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

Closed
wants to merge 1 commit into from
Closed

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Apr 21, 2023

Q A
Branch? 6.3
Bug fix? no
New feature? no
Deprecations? no
Tickets Fix #...
License MIT
Doc PR symfony/symfony-docs#...

Similar to #50087 this prevents file IO by re-ordering conditions.


There were even more similar code spots, but I wondered because they have different semantics
(different interpretation of success because of the placement of parantheses)

$ok = ($this->doUnlink($file) || !file_exists($file)) && $ok;

$ok = (!is_file($file) || $this->doUnlink($file) || !file_exists($file)) && $ok;

@nicolas-grekas
Copy link
Member

I don't think this is correct. These are guard checks to me, the order matters.

@stof
Copy link
Member

stof commented Apr 21, 2023

Well, switching the IO check and the boolean check is fine to me.

However, the ones linked in the description indeed can be changed as we cannot change the order for write IO operation (skipping a IO write is not an optimization opportunity)

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Apr 21, 2023

BUT, the check looks wrong to me!

it should be "unlink || !file_exists"!
Can you send a PR on 5.4?

@staabm staabm deleted the prevIO branch April 21, 2023 12:22
fabpot added a commit that referenced this pull request Apr 21, 2023
…abm)

This PR was merged into the 5.4 branch.

Discussion
----------

[Cache] Fix success interpretation when pruning cache

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tickets       | Fix #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exists, explain below instead -->
| License       | MIT
| Doc PR        | symfony/symfony-docs#... <!-- required for new features -->
<!--
Replace this notice by a short README for your feature/bugfix.
This will help reviewers and should be a good start for the documentation.

Additionally (see https://symfony.com/releases):
 - Always add tests and ensure they pass.
 - Bug fixes must be submitted against the lowest maintained branch where they apply
   (lowest branches are regularly merged to upper ones so they get the fixes too).
 - Features and deprecations must be submitted against the latest branch.
 - For new features, provide some code snippets to help understand usage.
 - Changelog entry should follow https://symfony.com/doc/current/contributing/code/conventions.html#writing-a-changelog-entry
 - Never break backward compatibility (see https://symfony.com/bc).
-->

As discussed in #50095 this PR fixes the interpretation when cache-pruning is considered successfull.

This is changed to use the same semantics used in other places of the codebase, e.g.

https://github.com/symfony/symfony/blob/51666290232ee13165c98fa9e40d3475a3cabfd8/src/Symfony/Component/Cache/Traits/FilesystemCommonTrait.php#L62
https://github.com/symfony/symfony/blob/51666290232ee13165c98fa9e40d3475a3cabfd8/src/Symfony/Component/Cache/Traits/FilesystemCommonTrait.php#L74

Commits
-------

76a2e62 [Cache] Fix success interpretation when pruning cache
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants