-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Conversation
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'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
() => manyArray
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
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); |
There was a problem hiding this comment.
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
...
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets keep the_
There was a problem hiding this comment.
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?
63df671
to
106f965
Compare
@stefanpenner @pangratz cleaned up |
|
||
internalModel.loadingData(promise); | ||
let cache = this._pendingFetch.getWithDefault(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#facepalm fixed @pangratz
106f965
to
1ed3cc4
Compare
|
||
for (let i = 0; i < totalItems; i++) { | ||
internalModels[i] = pendingFetchItems[i].internalModel; | ||
seeking[internalModels[i].id] = pendingFetchItems[i]; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 = []; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cache expectedInternalModels[i]
?
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rejectInternalModels
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cache group[j]._internalModel
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
1ed3cc4
to
7bd74df
Compare
resolver: resolver, | ||
options: options | ||
let modelClass = internalModel.type; | ||
let resolver = Ember.RSVP.defer('Fetching ' + modelClass.modelName + 'with id: ' + internalModel.id); |
There was a problem hiding this comment.
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 …'
7bd74df
to
85934c6
Compare
@pangratz updated |
…tionships and single records
85934c6
to
37c33e2
Compare
@bmac rebased |
…tionships and single records
Also underscores some store methods that are private that should have been before.