-
Couldn't load subscription status.
- Fork 11.6k
refactor: Some minor performance & readability enhancements #53596
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -109,9 +109,7 @@ public function dispatchNow($command, $handler = null) | |
| { | ||
| $uses = class_uses_recursive($command); | ||
|
|
||
| if (in_array(InteractsWithQueue::class, $uses) && | ||
| in_array(Queueable::class, $uses) && | ||
| ! $command->job) { | ||
| if (isset($uses[InteractsWithQueue::class], $uses[Queueable::class]) && ! $command->job) { | ||
| $command->setJob(new SyncJob($this->container, json_encode([]), 'sync', 'sync')); | ||
| } | ||
|
|
||
|
|
@@ -217,7 +215,7 @@ public function dispatchToQueue($command) | |
| { | ||
| $connection = $command->connection ?? null; | ||
|
|
||
| $queue = call_user_func($this->queueResolver, $connection); | ||
| $queue = ($this->queueResolver)($connection); | ||
|
|
||
| if (! $queue instanceof Queue) { | ||
| throw new RuntimeException('Queue resolver did not return a Queue implementation.'); | ||
|
|
@@ -239,19 +237,11 @@ public function dispatchToQueue($command) | |
| */ | ||
| protected function pushCommandToQueue($queue, $command) | ||
| { | ||
| if (isset($command->queue, $command->delay)) { | ||
| return $queue->laterOn($command->queue, $command->delay, $command); | ||
| } | ||
|
|
||
| if (isset($command->queue)) { | ||
| return $queue->pushOn($command->queue, $command); | ||
| } | ||
|
|
||
| if (isset($command->delay)) { | ||
| return $queue->later($command->delay, $command); | ||
| return $queue->later($command->delay, $command, queue: $command->queue ?? null); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it not possible to maintain using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @crynobone The methods aren't going anywhere, it's just unclear if there is any implementation that does anything except wrap the other functions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, just thinking if existing application using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Happy to back that part out, although those feel like brittle tests I don't think it's good to break things for the sake of breaking things. |
||
| } | ||
|
|
||
| return $queue->push($command); | ||
| return $queue->push($command, queue: $command->queue ?? null); | ||
| } | ||
|
|
||
| /** | ||
|
|
||
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.
This is an incorrect refactor. isset looks at the keys. in_array looks at the values.
Uh oh!
There was an error while loading. Please reload this page.
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.
Isn't
class_uses_recursive()outputting the exact same key as value?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.
@GrahamCampbell as @ralphjsmit points out, the result of
class_uses_recursive()is a key-value pair with the trait name for both, therefore you can useisset()to check for the usage of a trait (O(1)) rather than traverse the array till you find the value usingin_array(). (O(n))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.
This should be fine and we use
isset()as well forframework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithTestCaseLifecycle.php
Lines 196 to 220 in eb625fa
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.
@crynobone the
array_flip()in that example should probably be removed too… (unrelated to this PR)