@@ -134,17 +134,6 @@ function getIndex (state, id) {
134
134
return state . cylcTree . $index [ id ]
135
135
}
136
136
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
-
148
137
/* Add a child node under a parent Node */
149
138
function addChild ( parentNode , childNode ) {
150
139
// determine which list to add this node to
@@ -276,10 +265,11 @@ function cleanParents (state, node) {
276
265
*/
277
266
function applyInheritance ( state , node ) {
278
267
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 } , { } )
280
270
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
283
273
const childNode = getIndex ( state , child . id )
284
274
if ( childNode ) {
285
275
addChild ( node , childNode )
0 commit comments