-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
[Audit logs] Refactor the event hub #15128
Conversation
Codecov ReportBase: 59.86% // Head: 50.06% // Decreases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## feature/audit-logs #15128 +/- ##
======================================================
- Coverage 59.86% 50.06% -9.80%
======================================================
Files 1346 291 -1055
Lines 32757 10270 -22487
Branches 6182 2269 -3913
======================================================
- Hits 19609 5142 -14467
+ Misses 11301 4228 -7073
+ Partials 1847 900 -947
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
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.
🚀
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.
Looks good overall. I'm wondering if we could keep the EventEmitter inheritance 🤔
@@ -33,7 +33,7 @@ class WebhookRunner { | |||
this.queue = new WorkerQueue({ logger, concurrency: 5 }); | |||
this.queue.subscribe(this.executeListener.bind(this)); | |||
|
|||
strapi.eventHub.addSubscriber((eventName, ...args) => { | |||
strapi.eventHub.subscribe((eventName, ...args) => { |
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 think we don't need to subscribe to all the events because now we have the on function, so instead we can go to line 63 and add this.eventHub.on(event, listen)
like before this change
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 see what you mean, but I think the webhooks is a good use case for a single subscriber function
Before there was some duplicate logic: when a webhook was added, we had to both add a listener to the map, and to add a callback with on()
. And vice versa for removing a webhook
With this current solution, we have a single subscriber that directly reads the webhook map, which seems more efficient to me
@alexandrebodin are there other things that EventEmitter offers that we may need in the future? My concern would be that it may cause confusion since EventEmitter exposes many methods (including many aliases), and we'd be overriding some but not all of them |
That's actually the point of inheriting from a class to keep most of it's logic but extend it :) Look at this for example https://github.com/EventEmitter2/EventEmitter2. What we want isn't a new Module but rather the old one with a way to listen to all events :) If we can avoid breaking the eventHub at all I think that is worth the shot as I know some people are already using it |
@alexandrebodin thanks for the clarifying. The part that I just find weird about extending here is that we're only overriding To move forward with the class extension, is it okay if I expose |
d575684
to
6dced3a
Compare
@@ -32,14 +32,18 @@ class WebhookRunner { | |||
|
|||
this.queue = new WorkerQueue({ logger, concurrency: 5 }); | |||
this.queue.subscribe(this.executeListener.bind(this)); | |||
|
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.
Please avoid refactor the webhook system if not necessary. It could benefit from a subscribe function but that's not the goal of this PR and it would require more testing if you did.
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 understand that we want to reduce the risk by changing as little as possible, I'll update 👍
that's not the goal of this PR
Does this mean I could potentially reopen it as another dedicated PR in the future?
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 of course 👍 you can if you have bandwidth for sure with added tests etc :)
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.
LGTM. Good job!
What does it do?
Refactor
strapi.eventHub
:Only use one single subscriber for the webhooks feature, and rely on the listeners map to decide whether a callback should runWhy is it needed?
How to test it?
I tested the changes manually but we'll need to do serious QA on this at the feature level before releasing audit logs.