Skip to content

Commit

Permalink
feedback better unload; use graph colouring rather than allocating array
Browse files Browse the repository at this point in the history
  • Loading branch information
hjdivad committed Oct 21, 2016
1 parent cd119ed commit 347c3d7
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions addon/-private/system/model/internal-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,13 @@ export default function InternalModel(type, id, store, _, data) {
when we are deleted
*/
this._implicitRelationships = new EmptyObject();

// Used for coloring during BFS
this._bfsId = 0;
}

let nextBfsId = 1;

InternalModel.prototype = {
isEmpty: retrieveFromCurrentState('isEmpty'),
isLoading: retrieveFromCurrentState('isLoading'),
Expand Down Expand Up @@ -254,17 +259,17 @@ InternalModel.prototype = {
allRelatedInternalModels() {
let array = [];
let queue = [];
let seen = [];
let bfsId = nextBfsId++;
queue.push(this);
seen.push(this);
this._bfsId = bfsId;
while (queue.length > 0) {
let node = queue.shift();
array.push(node);
let related = node.directlyRelatedInternalModels();
related.forEach(internalModel => {
if (seen.indexOf(internalModel) === -1) {
if (internalModel._bfsId < bfsId) {
queue.push(internalModel);
seen.push(internalModel);
internalModel._bfsId = bfsId;
}
});
}
Expand Down

0 comments on commit 347c3d7

Please sign in to comment.