Skip to content

Commit

Permalink
Merge pull request #1623 from oliver-sanders/store.applyInheritance-s…
Browse files Browse the repository at this point in the history
…peedup

store: more efficient family tree building
  • Loading branch information
wxtim authored Jan 17, 2024
2 parents 057aad8 + b3ec0e1 commit c8e24f1
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions src/store/workflows.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,6 @@ function getIndex (state, id) {
return state.cylcTree.$index[id]
}

/* Return true if a node has at least one child.
*
* Defaults to looking in node.children, set childAttr to use a different
* tree (e.g. familyTree).
*/
function hasChild (node, id, attr = 'id', childAttr = 'children') {
return node[childAttr].some(
item => item[attr] === id
)
}

/* Add a child node under a parent Node */
function addChild (parentNode, childNode) {
// determine which list to add this node to
Expand Down Expand Up @@ -276,10 +265,11 @@ function cleanParents (state, node) {
*/
function applyInheritance (state, node) {
if (node.type === 'family' && node.node.childTasks) {
// add new tasks
// build a mapping of {childID: childNode} for faster lookup
const childIDs = node.children.reduce((map, obj) => { map[obj.id] = obj; return map }, {})
for (const child of node.node.childTasks) {
if (!hasChild(node, child.id)) {
// child has been added to childTasks
if (!(child.id in childIDs)) {
// add any new tasks to the family
const childNode = getIndex(state, child.id)
if (childNode) {
addChild(node, childNode)
Expand Down

0 comments on commit c8e24f1

Please sign in to comment.