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

chore(store): cleans up and optimizes code paths around fetching rela… #4617

Merged
merged 1 commit into from
Oct 28, 2016

Conversation

runspired
Copy link
Contributor

…tionships and single records

Also underscores some store methods that are private that should have been before.

this._loadingPromise = promiseManyArray(this.store.scheduleFetchMany(manyArray.toArray()).then(() => {
return manyArray;
}), 'Reload with ids');
this._loadingPromise = promiseManyArray(this.store._scheduleFetchMany(manyArray.currentState).then(() => { return manyArray; }), 'Reload with ids');
Copy link
Member

Choose a reason for hiding this comment

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

() => manyArray

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@igorT
Copy link
Member

igorT commented Oct 22, 2016

Seems good, I'll give it a once over once less tired

} else {
this._pendingFetch.get(typeClass).push(pendingFetchItem);
this._pendingFetch.get(modelClass).push(pendingFetchItem);
Copy link
Member

@pangratz pangratz Oct 22, 2016

Choose a reason for hiding this comment

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

This if/else could be handled more elegantly using MapWithDefault...

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 may also be better to just create a hash via modelName, I don't think we need to go all the way to a map here.

Copy link
Member

Choose a reason for hiding this comment

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

Now that we're using MapWithDefault, this can be shortened to this._pendingFetch.get(modelClass).push(pendingFetchItem).

@private
@param {Object} preload
*/
_preloadData(preload) {
Copy link
Member

Choose a reason for hiding this comment

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

lets keep the_

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@stefanpenner I removed this one because InternalModel is "entirely private api" and this is used by other private modules, I believe that was our stated api naming goal?

@runspired runspired force-pushed the cleanup-many-array-reload branch from 63df671 to 106f965 Compare October 22, 2016 14:13
@runspired
Copy link
Contributor Author

@stefanpenner @pangratz cleaned up


internalModel.loadingData(promise);
let cache = this._pendingFetch.getWithDefault();
Copy link
Member

Choose a reason for hiding this comment

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

What does this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#facepalm fixed @pangratz

@runspired runspired force-pushed the cleanup-many-array-reload branch from 106f965 to 1ed3cc4 Compare October 22, 2016 14:30

for (let i = 0; i < totalItems; i++) {
internalModels[i] = pendingFetchItems[i].internalModel;
seeking[internalModels[i].id] = pendingFetchItems[i];
Copy link
Member

Choose a reason for hiding this comment

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

Do we want to cache pendigFetchItems[i] so the lookup only happens once? This would also allow to get the internalModel's id from the cached result without looking it up again.

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 debated on this, the alternative is:

let pendingItem = pendingFetchItems[i];
let internalModel = pendingItem.internalModel;
internalModels[i] = internalModel;
seeking[internalModel.id] = pendingItem;

This may be more clear but I'm not sure the "cache" actually is any simpler.

Copy link
Member

Choose a reason for hiding this comment

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

I would be in favor of better readability here


function _fetchRecord(recordResolverPair) {
recordResolverPair.resolver.resolve(store.fetchRecord(recordResolverPair.record, recordResolverPair.options)); // TODO adapter options
recordResolverPair.resolver.resolve(store._fetchRecord(recordResolverPair.internalModel, recordResolverPair.options)); // TODO adapter options
Copy link
Member

Choose a reason for hiding this comment

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

Let's split this into separate statements for better readability.

Copy link
Contributor Author

@runspired runspired Oct 22, 2016

Choose a reason for hiding this comment

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

like so?

recordResolverPair.resolver.resolve(
  store._fetchRecord(recordResolverPair.internalModel,
  recordResolverPair.options)
); // TODO adapter options

Copy link
Member

Choose a reason for hiding this comment

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

I meant something like:

let fetchRecord = store._fetchRecord();
recordResolverPair.resolver.resolve(fetchRecord);

id: 'ds.store.missing-records-from-adapter'
});
// reject missing records
let missingRecords = [];
Copy link
Member

Choose a reason for hiding this comment

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

Rename to missingInternalModels to better reflect what they are containig

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

let missingRecords = [];
for (let i = 0, l = expectedInternalModels.length; i < l; i++) {
if (!found[expectedInternalModels[i].id]) {
missingRecords.push(expectedInternalModels[i]);
Copy link
Member

Choose a reason for hiding this comment

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

Cache expectedInternalModels[i]?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same argument as above, I always go back and forth on this. Saving one index access vs one assignment. Perf wise it's likely ignorable, but readability is a bit better.

rejectRecords(records, error);
};
}
function rejectRecords(internalModels, error) {
Copy link
Member

Choose a reason for hiding this comment

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

rejectInternalModels

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

then(null, makeRecordsRejector(requestedRecords));
for (let j = 0; j < totalInGroup; j++) {
groupedInternalModels[j] = group[j]._internalModel;
ids[j] = groupedInternalModels[j].id;
Copy link
Member

Choose a reason for hiding this comment

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

Cache group[j]._internalModel

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@runspired runspired force-pushed the cleanup-many-array-reload branch from 1ed3cc4 to 7bd74df Compare October 22, 2016 15:48
resolver: resolver,
options: options
let modelClass = internalModel.type;
let resolver = Ember.RSVP.defer('Fetching ' + modelClass.modelName + 'with id: ' + internalModel.id);
Copy link
Member

Choose a reason for hiding this comment

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

Missing space after modelClass.modelName + 'with …'

@runspired runspired force-pushed the cleanup-many-array-reload branch from 7bd74df to 85934c6 Compare October 27, 2016 15:14
@runspired
Copy link
Contributor Author

@pangratz updated

@runspired runspired force-pushed the cleanup-many-array-reload branch from 85934c6 to 37c33e2 Compare October 28, 2016 19:11
@runspired
Copy link
Contributor Author

@bmac rebased

@bmac bmac merged commit d0a3bbb into emberjs:master Oct 28, 2016
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.

5 participants