-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Finder] Use a lazyIterator to close files descriptors when no longer used #40040
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
Conversation
b984368
to
c1b3e9b
Compare
Hey! This is.. this is amazing. Thank you! I think @hurricane-voronin has recently worked with this code. Maybe they can help review this? Cheers! Carsonbot |
1788517
to
cb94f87
Compare
im wondering if eg.
roughly :) |
That's not possible, edit: I missed the trick with |
Refactored to use IteratorAggregate . |
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.
👍🏻 for LazyIterator as feature also, given Finder::append() supports aggregates, eg. Finder::append(new LazyIterator($callable))
works.
Thank you @jderusse. |
/** | ||
* @author Jérémy Derussé <jeremy@derusse.com> | ||
*/ | ||
class LazyIterator implements \IteratorAggregate |
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.
should we mark it as @internal
?
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 agree, see #40163
This PR was merged into the 4.4 branch. Discussion ---------- [Finder] mark the LazyIterator class as internal | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | #40040 (comment) | License | MIT | Doc PR | Commits ------- 4a2c996 mark the LazyIterator class as internal
This PR was merged into the 4.4 branch. Discussion ---------- [Finder] mark the LazyIterator class as internal | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | symfony/symfony#40040 (comment) | License | MIT | Doc PR | Commits ------- 8e69df8 mark the LazyIterator class as internal
The
RecursiveDirectoryIterator
class open the file on__construct
.Because we Inject an instance of
RecursiveDirectoryIterator
inside the \AppendIterator` class, php opens a lot of file even before iterating on it.This PR adds a new
LazyIterator
class that instantiate the decorated class only when something starts iterating on it.When the iteration is over, it unset the variable to close let the decorated class clean things (ie. close the files)