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

Soft delete doubles calls for service.get #161

Closed
NikitaVlaznev opened this issue Apr 24, 2017 · 2 comments
Closed

Soft delete doubles calls for service.get #161

NikitaVlaznev opened this issue Apr 24, 2017 · 2 comments

Comments

@NikitaVlaznev
Copy link
Contributor

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, 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 code points:

case 'get':
  return throwIfItemDeleted(hook.id)
    .then((data) => {

...

function throwIfItemDeleted (id) {
  return service.get(id, { query: { $disableSoftDelete: true } })
    .then(data => {
@NikitaVlaznev
Copy link
Contributor Author

Here is the PR for that: #160.

@eddyystop
Copy link
Collaborator

Discussion moved to that PR.

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

2 participants