-
Notifications
You must be signed in to change notification settings - Fork 11.2k
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
[9.x] Get last item of takeUntilTimeout
method on a LazyCollection
#41275
[9.x] Get last item of takeUntilTimeout
method on a LazyCollection
#41275
Conversation
I'm not really familiar with the types of static analysis. Can anyone help me and tell me what I did wrong? 🤔 |
Hmmm. This actually surfaced a bug in the current implementation of Instead of the implementation here, I think we should instead fix It's gonna be a little more work in the callback, but I think that's more correct. |
@gdebrauwer do you know how to address @JosephSilber's comments? |
This PR changes the public interface so it should target master. |
@gdebrauwer if you need help, just say the word and I'm there with assistance. |
This pull request should target |
@netpok @nunomaduro is the fear that people are overriding |
For me it's more like "a major version means there won't be a breaking change" thing, also php already provides "magical ways" to add additional parameters to a function without breaking compatibility: public function takeUntilTimeout(DateTimeInterface $timeout)
{
$callback = func_num_args() > 1 ? func_get_arg(1) : null;
// rest of code...
} |
I created a seperate PR that fixes the implementation of the method. Let me know what I should do this PR: target |
@gdebrauwer is this PR superseded by #41370? |
That PR fixes an issue that was already present in the |
An extra argument is added to a method here so it should target master. Thanks |
@gdebrauwer it does not matter if its an optional parameter. Take a look here: https://3v4l.org/h5gkL |
This PR allows the
takeUntilTimeout
method of aLazyCollection
to accept a second parameter: a closure. This closure will be executed when the timeout has been reach and it will return the first item that it was not able to process anymore.Why?
Sometimes you need to process a lot of data in a job and you can not do it in one job because the job will timeout. Let's say you have thousands of users that need to be processed.
This job will timeout if there a lot of users. This is were the current
takeUntilTimeout
method comes into play. We could just process users until we reach the timeout, but than we still need to know which users we have not processed yet. So we need to keep track of the last processed user in order to prevent duplicate processing. This creates a lot of overhead code which will be the same in every job that processes lots of data.This can be simplified if the
takeUntilTimeout
returns the first item that it could not process anymore. Now we can just dispatch a new job from inside that closure and we don't need a that boilerplate code anymore.