Skip to content

Commit c8e24f1

Browse files
authored
Merge pull request #1623 from oliver-sanders/store.applyInheritance-speedup
store: more efficient family tree building
2 parents 057aad8 + b3ec0e1 commit c8e24f1

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

src/store/workflows.module.js

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -134,17 +134,6 @@ function getIndex (state, id) {
134134
return state.cylcTree.$index[id]
135135
}
136136

137-
/* Return true if a node has at least one child.
138-
*
139-
* Defaults to looking in node.children, set childAttr to use a different
140-
* tree (e.g. familyTree).
141-
*/
142-
function hasChild (node, id, attr = 'id', childAttr = 'children') {
143-
return node[childAttr].some(
144-
item => item[attr] === id
145-
)
146-
}
147-
148137
/* Add a child node under a parent Node */
149138
function addChild (parentNode, childNode) {
150139
// determine which list to add this node to
@@ -276,10 +265,11 @@ function cleanParents (state, node) {
276265
*/
277266
function applyInheritance (state, node) {
278267
if (node.type === 'family' && node.node.childTasks) {
279-
// add new tasks
268+
// build a mapping of {childID: childNode} for faster lookup
269+
const childIDs = node.children.reduce((map, obj) => { map[obj.id] = obj; return map }, {})
280270
for (const child of node.node.childTasks) {
281-
if (!hasChild(node, child.id)) {
282-
// child has been added to childTasks
271+
if (!(child.id in childIDs)) {
272+
// add any new tasks to the family
283273
const childNode = getIndex(state, child.id)
284274
if (childNode) {
285275
addChild(node, childNode)

0 commit comments

Comments
 (0)