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

Optimise has many notifications #4850

Merged
merged 7 commits into from
Mar 10, 2017
Merged

Optimise has many notifications #4850

merged 7 commits into from
Mar 10, 2017

Conversation

BryanCrotaz
Copy link
Contributor

@BryanCrotaz BryanCrotaz commented Mar 9, 2017

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()

Copy link
Member

@hjdivad hjdivad left a 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.

@BryanCrotaz
Copy link
Contributor Author

Good point.

// 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)) {
Copy link
Member

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.

Copy link
Member

@stefanpenner stefanpenner left a 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

removedCount: <integer> // 0 if no change
}
*/
const diffArray = function (oldArray, newArray) {
Copy link
Member

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

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(
Copy link
Member

Choose a reason for hiding this comment

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

lets leave let here

//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);
Copy link
Member

Choose a reason for hiding this comment

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

let


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);
Copy link
Member

Choose a reason for hiding this comment

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

let

@stefanpenner
Copy link
Member

eslint looks unhappy:

 18) [PhantomJS 2.1] ESLint - modules/ember-data/-private/system/diff-array.js: should pass ESLint
     modules/ember-data/-private/system/diff-array.js should pass ESLint.
58:2  - Unnecessary semicolon. (no-extra-semi)
     expected: true
       actual: false
     http://localhost:7357/assets/dummy.js:159:14
     runTest@http://localhost:7357/assets/test-support.js:849:32
     run@http://localhost:7357/assets/test-support.js:834:11
     http://localhost:7357/assets/test-support.js:976:14
     process@http://localhost:7357/assets/test-support.js:635:24
     begin@http://localhost:7357/assets/test-support.js:617:9
     http://localhost:7357/assets/test-support.js:677:9

@stefanpenner stefanpenner merged commit 03440c1 into emberjs:master Mar 10, 2017
@stefanpenner
Copy link
Member

🎉 🎉 🎉

@BryanCrotaz
Copy link
Contributor Author

:) We got there eventually

@stefanpenner
Copy link
Member

stefanpenner commented Mar 10, 2017

between this and #4842 hasMany relationships have gotten some good TLC these last few weeks.

@BryanCrotaz
Copy link
Contributor Author

I just found another 10x improvement... more to come

@stefanpenner
Copy link
Member

@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!

@BryanCrotaz
Copy link
Contributor Author

@stefanpenner this is what we're working on...

runspired added a commit to runspired/data that referenced this pull request Apr 25, 2018
runspired added a commit that referenced this pull request Apr 25, 2018
Revert "Optimise has many notifications (#4850)"
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

Successfully merging this pull request may close these issues.

3 participants