-
-
Notifications
You must be signed in to change notification settings - Fork 751
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
Using hooks with arrays causes after hooks to run x number of times. #218
Comments
It's actually running the hooks data.length number of times. |
Found it: These ones are different: I think this one would even work and not call hooks repeatedly: |
If this is the behavior that we expect, then we probably do not want hooks to handle arrays. It would be better for hooks to ignore arrays and only process single objects. I change my mind. It doesn't make sense to not take advantage of bulk updates. |
Sequelize, nedb, waterline, and mongodb are different. I think the This is the way that makes more sense to me. Instead of doing x number of rapid-fire requests to the database, it seems smarter to take advantage of the bulk update feature (that's present in all of the main db adapters) and make a single request to the database. We already have the code in place to provide events for all of the items in the array, which is really the only thing that I think needs to be done individually. |
This is a great catch. Thinking about it (on a Friday night past wine'o clock) I would say the adapters need to have a way to call the original methods without any mixin functionality. One way might be to just store the original methods as There was similar problems when using pagination. feathersjs-ecosystem/feathers-sequelize#8 is very likely related to this. |
I think we definitely want to treat arrays as single requests to the db, otherwise our apps will hit 5000+ requests per second much too easily. |
I don't think it is that common to The specific problem here, that hooks and other mixins should not run if the method is called internally and the issue I referenced can probably be fixed by simply adding a |
I'm not as concerned about thousands of item in an array as I am about a couple hundred with a lot of users. I'm able to get |
OK. It took me a while to figure out how |
I'm doing an update of the database adapters today (just like feathersjs-ecosystem/feathers-memory#13). Just keeping track of which ones I've done: |
@marshallswain great find man! I know @corymsmith ran into this a couple times but he wasn't sure if he was just doing something wrong. |
Thanks! I think this is what was causing issues for @BigAB the other day, too. |
All database adapters have been updated accordingly. Closing this issue now. |
@daffl I'm running into this issue again using |
This is a different issue, tracked in feathersjs-ecosystem/feathers-rethinkdb#80 |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue with a link to this issue for related bugs. |
I discovered this odd behavior by using an afterHook on
create
with a beforeHook on another service'screate
. I'm not sure where this is happening, yet. Update: it's due to how some of the adapters handle arrays.Below is an example to duplicate the issue. Switch between the create statements and you'll see the difference.
Here's the output when creating a single object:
Here's the output when using create with the array:
The text was updated successfully, but these errors were encountered: