From 90f45a0df27bbc06d06cab89820232e501b07bbb Mon Sep 17 00:00:00 2001 From: "Kritagya Bhattarai (CalfMoon)" Date: Fri, 27 Mar 2026 22:29:24 +0545 Subject: [PATCH] fix: random size after timelapse timelapse caused the order in array to be changed which messed up the cache, no longer a problem with hashmap --- src/main.ts | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/main.ts b/src/main.ts index 82bdcb9..5d754eb 100644 --- a/src/main.ts +++ b/src/main.ts @@ -9,12 +9,6 @@ export default class NodeFactor extends Plugin { // stops loop when graph isn't open private updateLoop: boolean; - // This is a hash map that helps in specifically optimizing the forward tree - private treeOptimizeMap: Map = new Map(); - - // This array helps in optimizing the whole calculation process - private storedSized: Array = []; - async onload() { await this.loadSettings(); this.addSettingTab(new NodeFactorSettingTab(this.app, this)); @@ -64,15 +58,16 @@ export default class NodeFactor extends Plugin { }, 10); } + private storedSize: Map = new Map(); private updateNodes(nodes: ObsidianNode[]) { this.treeOptimizeMap.clear(); nodes.forEach((node, i) => { let weight: number; - if (this.storedSized[i] != undefined) { - weight = this.storedSized[i]; + if (this.storedSize.get(node.id) != undefined) { + weight = this.storedSize.get(node.id) as number; } else { weight = this.calcNodeWeight(node); - this.storedSized[i] = weight; + this.storedSize.set(node.id, weight); } node.weight = weight; }); @@ -104,6 +99,7 @@ export default class NodeFactor extends Plugin { return file.stat.size; } + private treeOptimizeMap: Map = new Map(); private fwdNodeTreeSize( node: ObsidianNode, antiLoopSet: Set, @@ -133,7 +129,7 @@ export default class NodeFactor extends Plugin { } clearSizeCache() { - this.storedSized = []; + this.storedSize.clear(); } async loadSettings() {