Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
3bec20ec
Commit
3bec20ec
authored
Sep 01, 2021
by
Sarah GP
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve recursive ancestoring
parent
23716539
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
17 deletions
+17
-17
app/assets/javascripts/pipelines/components/parsing_utils.js
app/assets/javascripts/pipelines/components/parsing_utils.js
+17
-17
No files found.
app/assets/javascripts/pipelines/components/parsing_utils.js
View file @
3bec20ec
...
...
@@ -52,6 +52,19 @@ export const createNodeDict = (nodes) => {
},
{});
};
/*
A peformant alternative to lodash's isEqual. Because findIndex always finds
the first instance of a match, if the found index is not the first, we know
it is in fact a duplicate.
*/
const
deduplicate
=
(
item
,
itemIndex
,
arr
)
=>
{
const
foundIdx
=
arr
.
findIndex
((
test
)
=>
{
return
test
.
source
===
item
.
source
&&
test
.
target
===
item
.
target
;
});
return
foundIdx
===
itemIndex
;
};
export
const
makeLinksFromNodes
=
(
nodes
,
nodeDict
)
=>
{
const
constantLinkValue
=
10
;
// all links are the same weight
return
nodes
...
...
@@ -83,7 +96,8 @@ export const getAllAncestors = (nodes, nodeDict) => {
return
nodeDict
[
node
]?.
needs
||
''
;
})
.
flat
()
.
filter
(
Boolean
);
.
filter
(
Boolean
)
.
filter
(
deduplicate
);
if
(
needs
.
length
)
{
return
[...
needs
,
...
getAllAncestors
(
needs
,
nodeDict
)];
...
...
@@ -108,29 +122,15 @@ export const filterByAncestors = (links, nodeDict) =>
const
targetNode
=
target
;
const
targetNodeNeeds
=
nodeDict
[
targetNode
].
needs
;
const
targetNodeNeedsMinusSource
=
targetNodeNeeds
.
filter
((
need
)
=>
need
!==
source
);
const
allAncestors
=
getAllAncestors
(
targetNodeNeedsMinusSource
,
nodeDict
);
return
!
allAncestors
.
includes
(
source
);
});
/*
A peformant alternative to lodash's isEqual. Because findIndex always finds
the first instance of a match, if the found index is not the first, we know
it is in fact a duplicate.
*/
const
deduplicate
=
(
item
,
itemIndex
,
arr
)
=>
{
const
foundIdx
=
arr
.
findIndex
((
test
)
=>
{
return
test
.
source
===
item
.
source
&&
test
.
target
===
item
.
target
;
});
return
foundIdx
===
itemIndex
;
};
export
const
parseData
=
(
nodes
)
=>
{
const
nodeDict
=
createNodeDict
(
nodes
);
const
allLinks
=
makeLinksFromNodes
(
nodes
,
nodeDict
);
const
filteredLinks
=
filterByAncestors
(
allLinks
,
nodeDict
);
const
links
=
filter
edLinks
.
filter
(
deduplicate
);
const
filteredLinks
=
allLinks
.
filter
(
deduplicate
);
const
links
=
filter
ByAncestors
(
filteredLinks
,
nodeDict
);
return
{
nodes
,
links
};
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment