Optimized code
This commit is contained in:
parent
566c48166e
commit
ce2f750626
1 changed files with 37 additions and 49 deletions
|
|
@ -93,32 +93,34 @@ export function groupByFamily(data, baseClasses, left, flow?: NodeType[]) {
|
||||||
let arrOfPossibleInputs = [];
|
let arrOfPossibleInputs = [];
|
||||||
let arrOfPossibleOutputs = [];
|
let arrOfPossibleOutputs = [];
|
||||||
let checkedNodes = new Map();
|
let checkedNodes = new Map();
|
||||||
|
const excludeTypes = new Set([
|
||||||
|
"str",
|
||||||
|
"bool",
|
||||||
|
"float",
|
||||||
|
"code",
|
||||||
|
"prompt",
|
||||||
|
"file",
|
||||||
|
"int",
|
||||||
|
]);
|
||||||
|
|
||||||
|
const checkBaseClass = (t: any) =>
|
||||||
|
t.type &&
|
||||||
|
t.show &&
|
||||||
|
((!excludeTypes.has(t.type) && baseClassesSet.has(t.type)) ||
|
||||||
|
(t.input_types && t.input_types.some((x) => baseClassesSet.has(x))));
|
||||||
|
|
||||||
if (flow) {
|
if (flow) {
|
||||||
for (const node of flow) {
|
for (const node of flow) {
|
||||||
console.log(node, baseClassesSet, left);
|
const nodeData = node.data;
|
||||||
checkedNodes.set(node.data.type, {
|
const foundNode = checkedNodes.get(nodeData.type);
|
||||||
hasBaseClassInTemplate:
|
checkedNodes.set(nodeData.type, {
|
||||||
checkedNodes.get(node.data.type)?.hasBaseClassInTemplate ||
|
hasBaseClassInTemplate: checkedNodes.get(nodeData.type)?.hasBaseClassInTemplate || Object.values(nodeData.node.template).some(
|
||||||
Object.values(node.data.node.template).some(
|
checkBaseClass
|
||||||
(t: any) =>
|
|
||||||
t.type &&
|
|
||||||
t.show &&
|
|
||||||
((t.type !== "str" &&
|
|
||||||
t.type !== "bool" &&
|
|
||||||
t.type !== "float" &&
|
|
||||||
t.type !== "code" &&
|
|
||||||
t.type !== "prompt" &&
|
|
||||||
t.type !== "file" &&
|
|
||||||
t.type !== "int" &&
|
|
||||||
baseClassesSet.has(t.type)) ||
|
|
||||||
(t.input_types &&
|
|
||||||
t.input_types.some((x) => baseClassesSet.has(x))))
|
|
||||||
),
|
),
|
||||||
hasBaseClassInBaseClasses:
|
hasBaseClassInBaseClasses: checkedNodes.get(nodeData.type)?.hasBaseClassInBaseClasses || nodeData.node.base_classes.some((t) =>
|
||||||
checkedNodes.get(node.data.type)?.hasBaseClassInBaseClasses ||
|
baseClassesSet.has(t)
|
||||||
node.data.node.base_classes.some((t) => baseClassesSet.has(t)),
|
),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -127,35 +129,21 @@ export function groupByFamily(data, baseClasses, left, flow?: NodeType[]) {
|
||||||
tempOutputs = [];
|
tempOutputs = [];
|
||||||
|
|
||||||
for (const [n, node] of Object.entries(nodes)) {
|
for (const [n, node] of Object.entries(nodes)) {
|
||||||
let hasBaseClassInTemplate, hasBaseClassInBaseClasses;
|
let foundNode = checkedNodes.get(n);
|
||||||
const foundNode = checkedNodes.get(n);
|
if (!foundNode) {
|
||||||
|
foundNode = {
|
||||||
if (foundNode) {
|
hasBaseClassInTemplate: Object.values(node.template).some(
|
||||||
hasBaseClassInBaseClasses = foundNode.hasBaseClassInBaseClasses;
|
checkBaseClass
|
||||||
hasBaseClassInTemplate = foundNode.hasBaseClassInTemplate;
|
),
|
||||||
} else {
|
hasBaseClassInBaseClasses: node.base_classes.some((t) =>
|
||||||
hasBaseClassInTemplate = Object.values(node.template).some(
|
baseClassesSet.has(t)
|
||||||
(t: any) =>
|
),
|
||||||
t.type &&
|
};
|
||||||
t.show &&
|
checkedNodes.set(n, foundNode);
|
||||||
((t.type !== "str" &&
|
|
||||||
t.type !== "bool" &&
|
|
||||||
t.type !== "float" &&
|
|
||||||
t.type !== "code" &&
|
|
||||||
t.type !== "prompt" &&
|
|
||||||
t.type !== "file" &&
|
|
||||||
t.type !== "int" &&
|
|
||||||
baseClassesSet.has(t.type)) ||
|
|
||||||
(t.input_types &&
|
|
||||||
t.input_types.some((x) => baseClassesSet.has(x))))
|
|
||||||
);
|
|
||||||
hasBaseClassInBaseClasses = node.base_classes.some((t) =>
|
|
||||||
baseClassesSet.has(t)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasBaseClassInTemplate) tempInputs.push(n);
|
if (foundNode.hasBaseClassInTemplate) tempInputs.push(n);
|
||||||
if (hasBaseClassInBaseClasses) tempOutputs.push(n);
|
if (foundNode.hasBaseClassInBaseClasses) tempOutputs.push(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
const totalNodes = Object.keys(nodes).length;
|
const totalNodes = Object.keys(nodes).length;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue