Skip to content

[5.8] Prevent event cache from firing multiple times the same event(s)#28904

Merged
taylorotwell merged 1 commit intolaravel:5.8from
jf-m:fix/28872
Jun 21, 2019
Merged

[5.8] Prevent event cache from firing multiple times the same event(s)#28904
taylorotwell merged 1 commit intolaravel:5.8from
jf-m:fix/28872

Conversation

@jf-m
Copy link
Copy Markdown
Contributor

@jf-m jf-m commented Jun 20, 2019

This is a proposed solution for solving #28872 .

Changes explanations:

EventCacheCommand

  • The discoverEvents are cached only when shouldDiscoverEvents is true on the related providers, otherwise only the listens are cached.
  • I've changed the structure of events.php so the the events/Listeners are grouped by EventServiceProvider.
[
  [Arrayof EventServiceProviders] => [Arrayof Events] => [Arrayof Listeners] 
]

instead of the old structure :

[
   [Arrayof Events] => [Arrayof Listeners] 
]
  • I've changed array_merge to array_merge_recursive because it still is technically possible that a basic listen event is also inside a discovered event.

EventServiceProvider

  • The boot methods now calls a getEvents to get the events of both discover and listen
  • If the events are cached, the getEvents will return ONLY the events located under the name of the current EventServiceProvider in the events.php cache.
    Indeed, the $this->listens() are already cached and they are all located inside the cache file, so there is no need to merge the cache file with listens;
    There is also no need to check for shouldDiscoverEvents because it was already done inside the event:cache command.

I hope this helps, cheers !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants