Commit 1c5c191c authored by Andrew Fontaine's avatar Andrew Fontaine

Merge branch 'pipeline-links-replace-uniq' into 'master'

Pipeline data parsing: improve deduplicate performance

See merge request gitlab-org/gitlab!66283
parents 5c781322 12790c45
import { isEqual, memoize, uniqWith } from 'lodash'; import { memoize } from 'lodash';
import { createSankey } from './dag/drawing_utils'; import { createSankey } from './dag/drawing_utils';
/* /*
...@@ -113,11 +113,24 @@ export const filterByAncestors = (links, nodeDict) => ...@@ -113,11 +113,24 @@ export const filterByAncestors = (links, nodeDict) =>
return !allAncestors.includes(source); 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) => { export const parseData = (nodes) => {
const nodeDict = createNodeDict(nodes); const nodeDict = createNodeDict(nodes);
const allLinks = makeLinksFromNodes(nodes, nodeDict); const allLinks = makeLinksFromNodes(nodes, nodeDict);
const filteredLinks = filterByAncestors(allLinks, nodeDict); const filteredLinks = filterByAncestors(allLinks, nodeDict);
const links = uniqWith(filteredLinks, isEqual); const links = filteredLinks.filter(deduplicate);
return { nodes, links }; return { nodes, links };
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment