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

[WIP] [Feat] implements Schema to separate store logic and model description from the model layer. #4584

Closed
wants to merge 2 commits into from

Conversation

runspired
Copy link
Contributor

@runspired runspired commented Oct 18, 2016

TODO

  • Refactor areas where internal model is being used as schema
  • Move as much logic off of DS.Model methods as we can, since it's public API we'll need to continue exposing it on that class, just not use it ourselves.
  • Refactor InternalModel down to just a data/state container
  • ? Refactor Model methods to use schema for descriptor iteration (tricky because Map => EmptyObject ) ?
  • ? consider refactoring out relationshipMap, as it's almost certain to be greedy and allocates a bunch of arrays. While this may be better if we often iterate over relationships by related className, I suspect such iteration is rare ?
  • ? InternalModel._loadingPromise ?
  • ? debugSeal on InternalModel so we can find anywhere we're being bad currently ?

@runspired runspired force-pushed the feat/schema branch 2 times, most recently from 2396e4e to 1549c26 Compare October 18, 2016 18:37
var id = coerceId(inputId);
var internalModel = this.typeMapFor(typeClass).idToRecord[id];
let id = coerceId(inputId);
let internalModel = this.schemaFor(modelName).recordMap.idToRecord[id];
Copy link
Member

Choose a reason for hiding this comment

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

a few lines bellow you saying recordMap.idToRecord[id] holds records

var record = idToRecord[id];
let id = coerceId(inputId);
let schema = this.schemaFor(modelName);
let record = schema.recordMap.idToRecord[id];
Copy link
Member

Choose a reason for hiding this comment

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

a few lines up you saying recordMap.idToRecord[id] holds internalModels

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this should be internalModel, I was carrying over the old names and should have noticed the old one was bad :trollface:

idToRecord: new EmptyObject(),
records: [],
metadata: new EmptyObject(),
type: this.model
Copy link
Member

Choose a reason for hiding this comment

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

what is this.model?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's nothing, it should be this.modelClass

Copy link
Member

Choose a reason for hiding this comment

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

Are you keeping type here and bellow because it would be too much work for now to refactor everything?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tchak more or less yes, I actually went down the road of refactoring everything in an earlier spike, but the problem is that a few of these places leak to public code and I'm no sure if we consider this one to yet or not.


referenceFor(type, name) {
referenceFor(modelClass, name) {
Copy link
Member

Choose a reason for hiding this comment

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

here type is referring to relationship kind : hasMany or belongsTo

Copy link
Contributor Author

Choose a reason for hiding this comment

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

whoops, will change that back. I think maybe we should consistently refer to this as kind internally? I noticed this confusion in another spot too.

Copy link
Member

Choose a reason for hiding this comment

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

👍 for using kind instead of type

@runspired
Copy link
Contributor Author

Early results for this branch have it at roughly (4ms / 238 records of 1 type over the 28ms of the internal-model branch it branches off of (this branch does not include the cache upgrades currently). This is a happy surprise, because most of the perf improvements this unlocks have not been worked on yet.

@fivetanley
Copy link
Member

will give a second review tomorrow, but i am crying tears of joy right now.


get type() {
deprecate(`InternalModel.type has been deprecated in favor of InternalModel.modelClass`, {
id: 'ember-data.private.type-to-modelClass'
Copy link
Member

Choose a reason for hiding this comment

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

needs an until: "3.0"


referenceFor(type, name) {
referenceFor(modelClass, name) {
Copy link
Member

Choose a reason for hiding this comment

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

👍 for using kind instead of type

}
if (!this._serializer) {
throw new Error('Cant find serializer!');
}
Copy link
Member

Choose a reason for hiding this comment

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

Is this a leftover from refactoring? Do we need this check for an serializer, since there should always be a default serializer, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe it's just a left over check for something that was failing for me early in the process and can be removed

inverse = inverseSchema.relationships[inverseName];

assert("We found no inverse relationships by the name of '" + inverseName + "' on the '" + inverseSchema.modelName +
"' model. This is most likely due to a missing attribute on your model definition.", !Ember.isNone(inverse));
Copy link
Member

Choose a reason for hiding this comment

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

s/attribute/relationship/


if (this._schemas === null) {
this._schemas = new EmptyObject();
}
Copy link
Member

Choose a reason for hiding this comment

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

I think it makes sense to initialize this._schemas in the init.

*/
typeMapFor(typeClass) {
typeMapFor(modelClass) {
Copy link
Member

Choose a reason for hiding this comment

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

Should this be renamed to recordMapFor to better reflect what is returned?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@pangratz yes, but I suspect we leaked this publicly and should add a deprecation.

@runspired
Copy link
Contributor Author

I rebased this, but I I want to shrink it's scope a bit and reconsider things. I should be able to land this by end of day tomorrow by branching off of #4664 and moving parts of the schema into ClassMeta instead and discarding much of the rest.

I think this implementation at this point in time is too broad, because we will likely want to expose a primitive (not necessarily exactly this one) to adapters in place of modelClass, but this one is not ready for that. I have a plan, but it's happily more incremental, and will turn into multiple simpler PRs instead of one larger one.

@runspired
Copy link
Contributor Author

As luck would have it, once I started trying to port some of the iterator / model parse optimizations into DS.Model, turns out we still need this! :trollface: So nvm on the new direction, cleaning up this PR and shifting it's focus a wee bit to be an object tied more closely to DS.Model for now.

chore(modelClass): converts InternalModel.type to InternalModel.modelClass

houston, we have a schema

move typeMap into schema

port typeMapFor usage to schemaFor().recordMap

type/typeClass => modelClass, type => modelName
@runspired
Copy link
Contributor Author

Closing in favor of #4865

@runspired runspired closed this Mar 16, 2017
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.

4 participants