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 release] Enumerate relationships provided, not all on a given… #5150

Merged
merged 1 commit into from
Aug 31, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions addon/-private/system/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -2429,9 +2429,10 @@ Store = Service.extend({
// payload push. In the common case where we are pushing many more
// instances than types we want to minimize the cost of looking up the
// inverse map and the overhead of Ember.get adds up.
let modelNameToInverseMap = Object.create(null);
let modelNameToInverseMap;

for (let i = 0, l = pushed.length; i < l; i += 2) {
modelNameToInverseMap = modelNameToInverseMap || Object.create(null);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it worth preventing the ToBoolean conversion here e.g. (modelNameToInverseMap !== undefined)

Copy link
Member Author

@stefanpenner stefanpenner Aug 25, 2017

Choose a reason for hiding this comment

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

I believe the cost of ToBoolean coercion in this context is negligible. I could default modelNameToInverseMap to false though, if you would prefer. That would be a minimal enough change I would feel comfortable with, although this feels like pre-mature opt territory. Let me know

Copy link
Contributor

Choose a reason for hiding this comment

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

No this seems fine.

// This will convert relationships specified as IDs into DS.Model instances
// (possibly unloaded) and also create the data structures used to track
// relationships.
Expand Down Expand Up @@ -2870,13 +2871,8 @@ function isInverseRelationshipInitialized(store, internalModel, data, key, model
}

function setupRelationships(store, internalModel, data, modelNameToInverseMap) {
let relationships = internalModel._relationships;

internalModel.type.eachRelationship(relationshipName => {
if (!data.relationships[relationshipName]) {
return;
}

Object.keys(data.relationships).forEach(relationshipName => {
let relationships = internalModel._relationships;
let relationshipRequiresNotification = relationships.has(relationshipName) ||
isInverseRelationshipInitialized(store, internalModel, data, relationshipName, modelNameToInverseMap);

Expand Down