1
bypass update emit action if collection/field has't changed by an API call
Source: directus/directus#23758 · opened by @mahendraHegde
Summary
I have a collection called users and a json field called settings, I run an expensive task on action hook, when settings fields of a users is updated, i want to be able to skip this action if there was no change made to the the field by the update api call, i skip the action if payload.settings is undefined, but how can i skip the action if payload.settings === userBeforeUpdate.settings
Explored options,
1. in action, fetch the user and compare user.settings with payload.settings, this wont work because at this point DB is already updated and condition will always return true
2. in filter, check if the payload.settings is same as user.settings(by reading user from DB), if so, set some custom boolean field in payload(ex payload.settings.updated=true/false indicating, whether the update mutated the user or not. This works, but is there a cleaner and more optimal approach?
I have a collection called users and a json field called settings, I run an expensive task on action hook, when settings fields of a users is updated, i want to be able to skip this action if there was no change made to the the field by the update api call, i skip the action if payload.settings is undefined, but how can i skip the action if payload.settings === userBeforeUpdate.settings
Explored options,
1. in action, fetch the user and compare user.settings with payload.settings, this wont work because at this point DB is already updated and condition will always return true
2. in filter, check if the payload.settings is same as user.settings(by reading user from DB), if so, set some custom boolean field in payload(ex payload.settings.updated=true/false indicating, whether the update mutated the user or not. This works, but is there a cleaner and more optimal approach?
No pledges yet. Be the first to back this.
Comments
Similar requests
Emit Events control via the public API (and directus/sdk)
1 vote · 0 comments
Extensions emit C(R)UD actions
4 votes · 0 comments
A way for a hook to identify root calls
1 vote · 0 comments
Add `emitter` to flow extensions
4 votes · 0 comments
Ability to duplicate a collection or create collection templates
72 votes · 0 comments
No comments yet.