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

[BUGFIX FEAT] Preserve local hasMany changes during flushCanonical #5269

Conversation

hjdivad
Copy link
Member

@hjdivad hjdivad commented Dec 1, 2017

resolves #5269

When new data comes in via store.push for a many array, and
ManyArray.prototype.flushCanonical is invoked:

  • new, unpersisted records added to the relationship are correctly not discarded, but
  • persisted records added to the relationship are erroneously discarded
  • new, unpersisted removals from the relationship are erroneously discarded

paired with @rwjblue, fix and additional test by @runspired

@runspired runspired changed the title Add failing test Adds failing test for bad ManyArray state after flushCanonical Apr 4, 2018
@runspired
Copy link
Contributor

Kicked this off, it's still failing. I'm wondering if it wouldn't be best with these "long term goal" tests to merge them and skip them. If testem would work with Qunit.todo correctly that would be ideal.

@runspired
Copy link
Contributor

This test may be fixed by #4852

hjdivad and others added 2 commits April 22, 2018 13:35
When new data comes in via `store.push` for a many array, and
`ManyArray.prototype.flushCanonical` is invoked:
  - new, unpersisted records added to the relationship are correctly not discarded, but
  - persisted records added to the relationship are erroneously discarded
@runspired runspired force-pushed the hjdivad/failing-test-for-flushCanonical-discarding-local-changes branch from 47eef06 to 43e9a70 Compare April 22, 2018 23:36
@runspired runspired changed the title Adds failing test for bad ManyArray state after flushCanonical [BUGFIX FEAT] Preserve local hasMany changes during flushCanonical Apr 22, 2018
if (diff.firstChangeIndex === null) {
// no changes found
if (removalSet) {
// records that have been removed since last compute will need their inverses to be corrected
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aren't the local inverses updated synchronously when the record is initially removed?

return set;
}

export function computeChanges(oldArray, newArray, removalSet) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's document the semantics of this function

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

speaking of which we should probably not have it in diff-array as it's semantics are more specific than array diffing

if we don't want to keep it in relationships/state/has-many maybe move it to something like relationships/state/utils and perhaps rename it to computeHasManyChanges(previousCanonicalState, newCanonicalState, locallyRemoved)

return set;
}

export function computeChanges(oldArray, newArray, removalSet) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's also add a test for non-contiguous changes

return changeset;
}

let removedMembersSet = setForArray(oldArray.slice(diff.firstChangeIndex, diff.firstChangeIndex + diff.removedCount));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this actually the set of removed members or rather the range (as a set) that contains all removed members?

Since we scan the range it's not a correctness issue but it makes the code more confusing

}

let removedMembersSet = setForArray(oldArray.slice(diff.firstChangeIndex, diff.firstChangeIndex + diff.removedCount));
let changeBlockSet = setForArray(newArray.slice(diff.firstChangeIndex, diff.firstChangeIndex + diff.addedCount));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the change block? Isn't this the minimal contiguous range that includes all the added records?

I'm trying to see why the name isn't symmetrical with removedMembersSet

}
});

let flushCanonicalLater = false;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when is this var changed?

@hjdivad
Copy link
Member Author

hjdivad commented Apr 24, 2018

This test may be fixed by #4852

The PR is green; if we don't need the local changes we'll still want the tests i think

@runspired
Copy link
Contributor

Closing this in favor of a new attempt at a later point that takes into consideration RecordData.

@runspired runspired closed this Oct 4, 2018
@runspired
Copy link
Contributor

Actually, going to reopen this one and PR the todo tests while eliminating the attempted implementation.

@runspired runspired reopened this Oct 4, 2018
@runspired
Copy link
Contributor

Closing since stale, likely mostly addressed with #7493

@runspired runspired closed this May 4, 2021
@runspired runspired deleted the hjdivad/failing-test-for-flushCanonical-discarding-local-changes branch November 29, 2022 07:51
@runspired runspired added 🏷️ test This PR primarily adds tests for a feature and removed test-contribution labels Sep 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ test This PR primarily adds tests for a feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants