perf(update): prevent graph update from running multiple times at once

This commit is contained in:
Kritagya Bhattarai (CalfMoon) 2026-03-28 18:28:06 +05:45
parent 777de23d9a
commit 783607292d

View file

@ -40,6 +40,7 @@ export default class NodeFactor extends Plugin {
async onunload() {} async onunload() {}
private sizeCache: Map<string, number> = new Map(); private sizeCache: Map<string, number> = new Map();
private timeoutId: NodeJS.Timeout;
private updateGraph() { private updateGraph() {
const leaf = this.app.workspace.getLeavesOfType("graph").first(); const leaf = this.app.workspace.getLeavesOfType("graph").first();
// don't run if graph page isn't loaded // don't run if graph page isn't loaded
@ -51,7 +52,8 @@ export default class NodeFactor extends Plugin {
// Slight delay in calculations is needed to fix node size // Slight delay in calculations is needed to fix node size
// if graph view is initially opened when opening obsidian // if graph view is initially opened when opening obsidian
setTimeout(() => { clearTimeout(this.timeoutId);
this.timeoutId = setTimeout(() => {
nodes.forEach((node, _i) => { nodes.forEach((node, _i) => {
let weight = 0; let weight = 0;
if (this.sizeCache.get(node.id) != undefined) { if (this.sizeCache.get(node.id) != undefined) {