Skip to content

Commit

Permalink
feedback better unload
Browse files Browse the repository at this point in the history
  • Loading branch information
hjdivad committed Oct 21, 2016
1 parent 500cb03 commit 1ea007b
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions addon/-private/system/model/internal-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,12 +255,21 @@ InternalModel.prototype = {
return this.record;
},

directlyRelatedInternalModels() {
/**
Computes the set of internal models reachable from `this` across exactly one
relationship.
@return {Array} An array containing the internal models that `this` belongs
to or has many.
*/
_directlyRelatedInternalModels() {
let array = [];
this.type.eachRelationship((key, relationship) => {
if (this._relationships.has(key)) {
let related = this._relationships.get(key).members.toArray();
array.push(...related);
for (let i=0; i<related.length; ++i) {
array.push(related[i]);
}
}
});
return array;
Expand All @@ -276,7 +285,7 @@ InternalModel.prototype = {
@return {Array} An array including `this` and all internal models reachable
from `this`.
*/
allRelatedInternalModels() {
_allRelatedInternalModels() {
let array = [];
let queue = [];
let bfsId = nextBfsId++;
Expand All @@ -285,7 +294,7 @@ InternalModel.prototype = {
while (queue.length > 0) {
let node = queue.shift();
array.push(node);
let related = node.directlyRelatedInternalModels();
let related = node._directlyRelatedInternalModels();
for (let i=0; i<related.length; ++i) {
let internalModel = related[i];
if (internalModel._bfsId < bfsId) {
Expand All @@ -312,7 +321,7 @@ InternalModel.prototype = {
unloadRecord() {
this.send('unloadRecord');
this.dematerializeRecord();
let relatedInternalModels = this.allRelatedInternalModels();
let relatedInternalModels = this._allRelatedInternalModels();
if (areAllModelsUnloaded(relatedInternalModels)) {
for (let i=0; i<relatedInternalModels.length; ++i) {
let internalModel = relatedInternalModels[i];
Expand Down

0 comments on commit 1ea007b

Please sign in to comment.