-
Notifications
You must be signed in to change notification settings - Fork 11.4k
[12.x] perf: support iterables for event discovery paths
#55699
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
30a132d
to
0584d85
Compare
Can you revert all of the styling changes so it's easier to see the real changes. |
0584d85
to
07749cf
Compare
Yes, reverted |
$discovered, | ||
DiscoverEvents::within($directory, $this->eventDiscoveryBasePath()) | ||
); | ||
}, []); |
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 array_merge_recursive can be totally removed? Does this not break anything?
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.
Yes because the DiscoverEvents::within()
does the same thing with its double foreach
loops:
framework/src/Illuminate/Foundation/Events/DiscoverEvents.php
Lines 30 to 49 in ea17178
public static function within($listenerPath, $basePath) | |
{ | |
$listeners = new Collection(static::getListenerEvents( | |
Finder::create()->files()->in($listenerPath), $basePath | |
)); | |
$discoveredEvents = []; | |
foreach ($listeners as $listener => $events) { | |
foreach ($events as $event) { | |
if (! isset($discoveredEvents[$event])) { | |
$discoveredEvents[$event] = []; | |
} | |
$discoveredEvents[$event][] = $listener; | |
} | |
} | |
return $discoveredEvents; | |
} |
The Finder::in()
method can accept an array and we're able to process all the listeners at once instead of repeated calls for every directory and then having to merge all of the arrays into one large array
Thanks! |
Hello!
This adds support for passing iterables to discover events. It also improves the performance of the event discovery by allowing multiple directories to be passed to
DiscoverEvents::within()
.Motivation
We have many modules and want to discover all listeners in a
Listeners
directory, to do that we have the following:However, the problem is that the file system is walked on every request (adding ~30ms to the boot time) and this argument isn't even used when the events are cached---in short this is a wasted operation in production.
This PR will allow for something like the following (which does not walk the file system if the events are cached):
Thanks!