-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Optimise has many notifications #4850
Optimise has many notifications #4850
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have a test for changing multiple noncontiguous blocks?
eg
siblings: [1,4,6]
to
siblings: [1,2,3,4,5,6]
It looks like diffArray
will handle this case & report a change of index: 1, remove: 1, add: 4
but I'm not seeing a test for it.
Good point. |
addon/-private/system/many-array.js
Outdated
// we found a change | ||
this.arrayContentWillChange(diff.firstChangeIndex, diff.removedCount, diff.addedCount); | ||
// It’s possible the parent side of the relationship may have been unloaded by this point | ||
if (_objectIsAlive(this)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we are not alive, i think we should just skip the whole function, exiting at line 145.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some remaining nit-picks. Then this looks good to merge, thanks for this great contribution!
paired with @igorT
addon/-private/system/diff-array.js
Outdated
removedCount: <integer> // 0 if no change | ||
} | ||
*/ | ||
const diffArray = function (oldArray, newArray) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you mind if we do export default function diffArray
- This lets readers easily see (without scanning the full file) that this method is the default export
addon/-private/system/many-array.js
Outdated
let toSet = this.canonicalState; | ||
|
||
//a hack for not removing new records | ||
//TODO remove once we have proper diffing | ||
let newRecords = this.currentState.filter( | ||
const newRecords = this.currentState.filter( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets leave let
here
addon/-private/system/many-array.js
Outdated
//TODO Figure out to notify only on additions and maybe only if unloaded | ||
this.relationship.notifyHasManyChanged(); | ||
// diff to find changes | ||
const diff = diffArray(this.currentState, toSet); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let
addon/-private/system/many-array.js
Outdated
|
||
assert(`You cannot add '${type.modelName}' records to this polymorphic relationship.`, !get(this, 'isPolymorphic')); | ||
record = store.createRecord(type.modelName, hash); | ||
const record = store.createRecord(type.modelName, hash); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let
eslint looks unhappy:
|
🎉 🎉 🎉 |
:) We got there eventually |
between this and #4842 hasMany relationships have gotten some good TLC these last few weeks. |
I just found another 10x improvement... more to come |
@BryanCrotaz nice. We are also working on more perf things. Sounds like ember-data will be quite different perf wise soon. Can't wait to see what your working on! |
@stefanpenner this is what we're working on... |
This reverts commit 34aef62.
Revert "Optimise has many notifications (#4850)"
Diff many arrays properly to find the smallest contiguous block describing the change
Particularly important when polling server for changes with a repeating model.reload() or relationship.update()