Skip to content

Commit

Permalink
Merge pull request #3889 from trentmwillis/push-perf
Browse files Browse the repository at this point in the history
 [perf] minor adjustments to `store#push` flow
  • Loading branch information
stefanpenner committed Oct 26, 2015
2 parents 5c1a906 + 64547e2 commit 023d4c7
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions packages/ember-data/lib/system/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export let badIdFormatAssertion = '`id` has to be non-empty string or number';

var Backburner = Ember._Backburner || Ember.Backburner || Ember.__loader.require('backburner')['default'] || Ember.__loader.require('backburner')['Backburner'];
var Map = Ember.Map;
var isArray = Array.isArray || Ember.isArray;

//Shim Backburner.join
if (!Backburner.prototype.join) {
Expand Down Expand Up @@ -1444,8 +1445,7 @@ Store = Service.extend({
@param {Object} data
*/
_load: function(data) {
var id = coerceId(data.id);
var internalModel = this._internalModelForId(data.type, id);
var internalModel = this._internalModelForId(data.type, data.id);

internalModel.setupData(data);

Expand Down Expand Up @@ -1672,13 +1672,21 @@ Store = Service.extend({
updated.
*/
push: function(data) {
if (data.included) {
data.included.forEach((recordData) => this._pushInternalModel(recordData));
var included = data.included;
var i, length;
if (included) {
for (i = 0, length = included.length; i < length; i++) {
this._pushInternalModel(included[i]);
}
}

if (Ember.typeOf(data.data) === 'array') {
var internalModels = data.data.map((recordData) => this._pushInternalModel(recordData));
return internalModels.map((internalModel) => internalModel.getRecord());
if (isArray(data.data)) {
length = data.data.length;
var internalModels = new Array(length);
for (i = 0; i < length; i++) {
internalModels[i] = this._pushInternalModel(data.data[i]).getRecord();
}
return internalModels;
}

var internalModel = this._pushInternalModel(data.data || data);
Expand Down Expand Up @@ -2046,7 +2054,7 @@ function deserializeRecordId(store, key, relationship, id) {
return;
}

Ember.assert(`A ${relationship.parentType} record was pushed into the store with the value of ${key} being ${Ember.inspect(id)}, but ${key} is a belongsTo relationship so the value must not be an array. You should probably check your data payload or serializer.`, !Ember.isArray(id));
Ember.assert(`A ${relationship.parentType} record was pushed into the store with the value of ${key} being ${Ember.inspect(id)}, but ${key} is a belongsTo relationship so the value must not be an array. You should probably check your data payload or serializer.`, !isArray(id));

//TODO:Better asserts
return store._internalModelForId(id.type, id.id);
Expand All @@ -2057,7 +2065,7 @@ function deserializeRecordIds(store, key, relationship, ids) {
return;
}

Ember.assert(`A ${relationship.parentType} record was pushed into the store with the value of ${key} being '${Ember.inspect(ids)}', but ${key} is a hasMany relationship so the value must be an array. You should probably check your data payload or serializer.`, Ember.isArray(ids));
Ember.assert(`A ${relationship.parentType} record was pushed into the store with the value of ${key} being '${Ember.inspect(ids)}', but ${key} is a hasMany relationship so the value must be an array. You should probably check your data payload or serializer.`, isArray(ids));
return ids.map((id) => deserializeRecordId(store, key, relationship, id));
}

Expand Down

0 comments on commit 023d4c7

Please sign in to comment.