Skip to content
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

[Suggestion] Ability to disable default service events from being emitted #922

Closed
cdimitroulas opened this issue Aug 3, 2018 · 7 comments

Comments

@cdimitroulas
Copy link

At the moment I do not believe there is a way to disable the default events from being emitted when a service method call is completed e.g. created, patched, removed etc.

It would be good if those events could be disabled from being emitted. There are certain cases where real-time events are not necessary for a service but I have not been able to find a way to disable them. Normally, this would not be an issue but since we are using feathers-sync those events are also synced using mongodb.

We have been getting some Mubsub: broken cursor errors from time to time and I suspect they are due to really huge documents being saved in that collection (10,000+ lines) from one service which does some very large batch operations.

I am creating this issue to see if this suggestion is something that you would consider implement, or even if there is another solution to this problem that I have not discovered yet. Any help is much appreciated 🙏

@daffl
Copy link
Member

daffl commented Aug 4, 2018

Related to #862 but you can already return feathers.SKIP in your last hook which will skip sending events (which is just another hook, too).

@cdimitroulas
Copy link
Author

I see, I wasn't aware that the event emission was triggered as the last hook of the chain.

However - I'm not sure this is a suitable solution for us because this would also skip any other application-level after/finally hooks that exist, not just the one which emits events. Please correct me if this is not the case!

@daffl
Copy link
Member

daffl commented Aug 8, 2018

Yes, the best way would be to allow to skip it explicitly as in #862. We could also add a flag that is used by feathers-sync not to synchronize the event (in https://github.com/feathersjs-ecosystem/feathers-sync/blob/master/lib/core.js#L34) since that seems to be the bottleneck here.

@claustres
Copy link
Contributor

I can confirm the issue with a service creating/deleting a lot of individual objects but we don't want it to emit standard events because we use a custom event managing objects by batch. However, we face the broken cursor issue with mubsub when replicating our app, thanks for the workaround on this issue.

@daffl
Copy link
Member

daffl commented Apr 20, 2019

Skipping events in general will also bee available in the next release through #1270

@claustres
Copy link
Contributor

I tried to use the trick with a hook returning feathers.SKIP and observed a strange behavior. My app is composed of different modules and when importing the feathers.SKIP constant in the main app from the core feathers module to create the hook on a service it did not work, raising an error like hook for xxx method returned invalid hook object.

In the debugger I could see that this equality test failed although both objects were shown as Symbol(__feathersSkipHooks). When I changed the code to import the feathers.SKIP constant in the module where the error was raised instead of the app it worked.

My understanding is that even if you create two JS Symbols using the same description, they are actually unique, see eg https://www.keithcirkel.co.uk/metaprogramming-in-es6-symbols/. What seems to appear in my app is that there are different "instances" of the symbol created because there are multiple imports of feather core or commons modules. So you should probably not use Symbol('xxx') to create the constant but Symbol.for('xxx') instead to avoid this tricky bug IMHO.

@daffl
Copy link
Member

daffl commented Jun 6, 2019

Disabling sending the event is now possible in Feathers v4 by setting context.event = null;. See the Migration guide for more information on how to upgrade.

@daffl daffl closed this as completed Jun 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants