Skip to content

Commit

Permalink
only schedule flushAllPendingFetches once per pendingFetch flush (#4829)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanpenner authored Mar 1, 2017
1 parent 0cf6d90 commit a6f14ec
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions addon/-private/system/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,11 @@ const { Promise } = RSVP;
//an internal model and return it in a promiseObject. Useful for returning
//from find methods
function promiseRecord(internalModelPromise, label) {
let toReturn = internalModelPromise.then((internalModel) => internalModel.getRecord());
let toReturn = internalModelPromise.then(internalModel => internalModel.getRecord());

return promiseObject(toReturn, label);
}


let Store;

// Implementors Note:
Expand Down Expand Up @@ -815,7 +814,9 @@ Store = Service.extend({
},

_scheduleFetch(internalModel, options) {
if (internalModel._loadingPromise) { return internalModel._loadingPromise; }
if (internalModel._loadingPromise) {
return internalModel._loadingPromise;
}

let { id, modelName } = internalModel;
let resolver = RSVP.defer(`Fetching ${modelName}' with id: ${id}`);
Expand All @@ -828,9 +829,11 @@ Store = Service.extend({
let promise = resolver.promise;

internalModel.loadingData(promise);
this._pendingFetch.get(modelName).push(pendingFetchItem);
if (this._pendingFetch.size === 0) {
emberRun.schedule('afterRender', this, this.flushAllPendingFetches);
}

emberRun.scheduleOnce('afterRender', this, this.flushAllPendingFetches);
this._pendingFetch.get(modelName).push(pendingFetchItem);

return promise;
},
Expand Down

0 comments on commit a6f14ec

Please sign in to comment.