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

Lazily materialize DS.Models for app code, use InternalModel inside ED otherwise #3094

Merged
merged 1 commit into from
Jun 2, 2015

Conversation

igorT
Copy link
Member

@igorT igorT commented May 24, 2015

No description provided.

@@ -143,7 +148,7 @@ export default Ember.Object.extend(Ember.MutableArray, Ember.Evented, {
this.get('relationship').removeRecords(records);
}
if (objects) {
this.get('relationship').addRecords(objects, idx);
this.get('relationship').addRecords(map(objects, function(obj) { return obj.reference; }), idx);
Copy link
Member Author

Choose a reason for hiding this comment

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

Could use mapBy

@igorT
Copy link
Member Author

igorT commented May 24, 2015

Thanks @pangratz

@@ -887,8 +599,8 @@ var Model = Ember.Object.extend(Ember.Evented, {
and value is an [oldProp, newProp] array.
*/
changedAttributes: function() {
var oldData = get(this, '_data');
var newData = get(this, '_attributes');
var oldData = get(this.reference, '_data');
Copy link
Member

Choose a reason for hiding this comment

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

it seems like this logic should move into the reference object rather than reaching into its private api.

something like Reference.prototype.changedAttributes. Then this function becomes this.reference.changedAttributes()

@igorT igorT force-pushed the references branch 4 times, most recently from c18d9fa to 57074a4 Compare June 1, 2015 17:52
@igorT igorT changed the title references-wip to make for easier reviewing Lazily materialize DS.Models for app code, use InternalModel inside ED otherwise Jun 1, 2015
},

flushCanonical: function() {
//TODO make this smarter, currently its plenty stupid
var toSet = filter.call(this.canonicalState, function(record) {
return !record.get('isDeleted');
return !record.isDeleted();
Copy link
Member

Choose a reason for hiding this comment

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

Lets use internalModel here instead of record because record is already used both internally and externally to refer to an instance of a DS.Model.


constructor: InternalModel,
materializeRecord: function() {
// lookupFactory should really return an object that creates
Copy link
Member

Choose a reason for hiding this comment

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

should we guard + throw if a re-materialization occurs? That seems like an error we would like to fail fast on.

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

@tchak
Copy link
Member

tchak commented Jun 1, 2015

@igorT there is lot's of places where record should be internalModel. It seems important to make the naming consistent.

},

becameReady: function() {
var self = this;
Copy link
Member

Choose a reason for hiding this comment

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

Self is a real thing in the bowser / webWorkers. we should likely not shadow it. Instead lets call this internalModel

Or even better, use the non-closure retaining form of schedule

Ember.run.schedule('actions', this, this.store.recordArrayManager.recordWasLoaded, this)

Copy link
Member Author

Choose a reason for hiding this comment

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

Ember.run.schedule('actions', this.store.recordArrayManager, this.store.recordArrayManager.recordWasLoaded, this) was the right call

@stefanpenner
Copy link
Member

I provided some superficial feedback. It is a bit tricky to provide something more in-depth for such a large set of changes. I will try to do another pass in the morning.

@igorT
Copy link
Member Author

igorT commented Jun 1, 2015

@stefanpenner the annoying part is that the large part is just moving methods from model to internalModel but not sure how to make it easier to review. You did review some of old code and now we can improve it ;)

… DS.Model

This commit adds an `InternalModel` class that is now used everywhere inside ED
to represent models. This class is a fast Javascript object that contains all the data
that we know for a particular record. At the ED/App code boundaries, such as responses
to `find`, models being set/pushed to `belongsTo`/`hasMany` we convert between
internalModels and DS.Models.

This should be a huge performance win, because we now lazily create DS.Models which are
pretty slow to instantiate.

We need to wait for the new serializer/push refactor in order to use a `push` that does
not immediately materialize a record to get further perf gains. For now most of perf gains
if for foreign keys.
igorT added a commit that referenced this pull request Jun 2, 2015
Lazily materialize DS.Models for app code, use InternalModel inside ED otherwise
@igorT igorT merged commit 6d6c646 into master Jun 2, 2015
@bmac bmac deleted the references branch May 26, 2016 16:54
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.

None yet

6 participants