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

update by id function in audit mixin makes 3 db calls #33

Closed
mlakdawala-sf opened this issue Oct 11, 2022 · 1 comment
Closed

update by id function in audit mixin makes 3 db calls #33

mlakdawala-sf opened this issue Oct 11, 2022 · 1 comment
Assignees

Comments

@mlakdawala-sf
Copy link
Contributor

Describe the bug

In the below code there are 3 db transactions, one for before, one for updation and another one for fetching the updated data post the update transaction, i feel this can be reduced to two considering we have the before value and the update value, we can make a union of the two values, this has performance impact on the application.
Considering negative scenarios of unwanted values, the update operation should be sufficient enough invalidate those values.

  async updateById(
     id: ID,
     data: DataObject<M>,
     options?: AuditOptions,
   ): Promise<void> {
     if (options?.noAudit) {
       return super.updateById(id, data, options);
     }
     const before = await this.findById(id);
     // loopback repository internally calls updateAll so we don't want to create another log
     if (options) {
       options.noAudit = true;
     } else {
       options = {noAudit: true};
     }
     await super.updateById(id, data, options);
     const after = await this.findById(id);
yeshamavani added a commit that referenced this issue Nov 3, 2022
yeshamavani added a commit that referenced this issue Nov 3, 2022
* fix(core): reduce the updateById 3 DB calls to 2

GH-33

* docs(ci-cd): added PR template

GH-33
@samarpan-b
Copy link
Contributor

Fixed now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants