Soft delete will call service.get only once #160
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
If you have a users service covered with softDelete hook, then there will be 2 users.get calls for every request to it and to eny other service, that requires a populated user, e.g. services that are covered with restrictToRoles.
Since users.get most likely is fetching data from the database it is expensive, because database ops usually are the most expensive operations in request handling code.
It have a significant impact on performance in high load projects.
Second call appears when softDelete hook is calling service.get while already processing service.get request, it is needed to check whether the resource is deleted or not. But after this check we have a complete result already, this result was processed by all succeeding hooks, so we do not need to call service.get second time.
The patch is eliminating unnecessary call while keeping an ability to work in the old way.
The only problem here as i can see is that after hooks will be called twice, it is not guaranteed that they correctly process the same result twice, so it would be great to find an option to return the result skipping other hooks, otherwise it is better to set optimize=false by default.
Tests patch is not the best of possible i'm sure, it would be great to see proposals of how to make it better.
Issue: #161.