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

[REPLICATE_ATTRIBUTES] should check if tracked value has changed before updating #51

Closed
hariprasadiit opened this issue Mar 26, 2020 · 3 comments
Labels
enhancement New feature or request

Comments

@hariprasadiit
Copy link

hariprasadiit commented Mar 26, 2020

In the code whether the tracked attributes value has changed or not is not checked. This results in writes even if there's no change to tracked attributes.

// Check if atleast one of the attributes to be replicated was changed
      let relevantUpdate = false;
      Object.keys(newValue).forEach(changedAttribute => {
        if (trackedMasterAttributes[changedAttribute]) {
          relevantUpdate = true;
        }
      });

We should be comparing old values of tracked attributes to new values, like

// Check if atleast one of the attributes to be replicated was changed
      let relevantUpdate = false;
      Object.keys(newValue).forEach(changedAttribute => {
        if (trackedMasterAttributes[changedAttribute] && newValue[changedAttribute] !== oldValue[changedAttribute]) {
          relevantUpdate = true;
        }
      });
@anishkny
Copy link
Owner

Oh thats a great optimization @hariprasadiit! Although, did you mean:

if (
  trackedMasterAttributes[changedAttribute] &&
  (newValue[changedAttribute] !== oldValue[changedAttribute])
) {
  relevantUpdate = true;
}

i.e. its relevant only if old and new values are not equal.

@anishkny anishkny changed the title [REPLICATE_ATTRIBUTES] only checks if the change.after contains the tracked attributes. [REPLICATE_ATTRIBUTES] should check if tracked value has changed before updating Mar 26, 2020
@anishkny anishkny added the enhancement New feature or request label Mar 26, 2020
@hariprasadiit
Copy link
Author

yes, the values should not be equal. typo!!

@anishkny
Copy link
Owner

anishkny commented Dec 2, 2020

Fixed by #59

@anishkny anishkny closed this as completed Dec 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants