refactor(calc): use setTimeout instead of setInterval to loop

this was done as per suggestion of https://developer.mozilla.org/en-US/docs/Web/API/Window/setInterval , this makes it so that even if the task insides takes longer the tasks won't stack
This commit is contained in:
Kritagya Bhattarai (CalfMoon) 2025-03-09 21:46:45 +05:45
parent 04d5324e15
commit bdf1a746b2

View file

@ -24,28 +24,29 @@ export default class NodeFactor extends Plugin {
const start = performance.now();
const treeOptimizeMap: Map<string, number> = new Map();
nodes.forEach((node) => {
const weight = this.calcNodeWeight(node, treeOptimizeMap);
node.weight = weight;
});
// setInterval(() => {
// const treeOptimizeMap: Map<string, number> = new Map();
// nodes.forEach((node) => {
// const weight = this.calcNodeWeight(
// node,
// treeOptimizeMap,
// );
// node.weight = weight;
// });
// }, 10);
// this.calcLoop(nodes);
console.log(performance.now() - start);
}),
);
}
private calcLoop(nodes: ObsidianNode[]) {
setTimeout(() => {
const treeOptimizeMap: Map<string, number> = new Map();
nodes.forEach((node) => {
const weight = this.calcNodeWeight(node, treeOptimizeMap);
node.weight = weight;
});
this.calcLoop(nodes);
}, 10);
}
private calcNodeWeight(
node: ObsidianNode,
treeOptimizeMap: Map<string, number>,