Skip to content

Commit

Permalink
modelviewer/Node: internal caching due to performance
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivo Sonderegger committed Mar 1, 2021
1 parent d2f465c commit a06e504
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/meteoJS/modelviewer/Node.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ export class Node {
* @private
*/
this._resources = new Map();

/**
* @type Set<undefined|module:meteoJS/modelviewer/resource.Resource[]>
* @private
*/
this._resourcesCache = undefined;
}

/**
Expand Down Expand Up @@ -118,12 +124,16 @@ export class Node {
* @package
*/
get resources() {
if (this._resourcesCache !== undefined)
return this._resourcesCache;

let result = new Set();
for (let resources of this._resources.values()) {
for (let r of resources.values())
result.add(r);
}
return [...result];
this._resourcesCache = [...result];
return this._resourcesCache;
}

/**
Expand Down Expand Up @@ -152,6 +162,8 @@ export class Node {
this._resources.get(variable.variableCollection).add(resource);
});
});
if (addedCount)
this._resourcesCache = undefined;
return addedCount;
}

Expand All @@ -172,6 +184,8 @@ export class Node {
removedCount++;
});
});
if (removedCount)
this._resourcesCache = undefined;
return removedCount;
}

Expand Down

0 comments on commit a06e504

Please sign in to comment.