From 79766873c390e975156928b0757b5c7ee5b875cc Mon Sep 17 00:00:00 2001 From: Emile Date: Fri, 21 Jan 2022 09:43:41 +0100 Subject: [PATCH] fix: Performance much worse in latest version See #75 --- main.ts | 12 +++++++----- manifest.json | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/main.ts b/main.ts index 3b66233..2d8a1db 100644 --- a/main.ts +++ b/main.ts @@ -1,4 +1,4 @@ -import { Plugin, MarkdownView, Notice, App, editorViewField } from 'obsidian'; +import {Plugin, MarkdownView, Notice, App, editorViewField, debounce} from 'obsidian'; import SuperchargedLinksSettingTab from "src/settings/SuperchargedLinksSettingTab" import { updateElLinks, @@ -45,7 +45,8 @@ export default class SuperchargedLinks extends Plugin { // Removing those in favour of watching the containers // updateDivLinks(this.app, this.settings); })); - this.registerEvent(this.app.metadataCache.on('changed', (_file) => { + + this.registerEvent(this.app.metadataCache.on('changed', debounce((_file) => { updateVisibleLinks(this.app, this.settings); this.observers.forEach(([observer, type, own_class ]) => { const leaves = this.app.workspace.getLeavesOfType(type); @@ -53,7 +54,8 @@ export default class SuperchargedLinks extends Plugin { this.updateContainer(leaf.view.containerEl, this, own_class); }) }); - })); + // Debounced to prevent lag when writing + }, 4500, true))); const ext = Prec.lowest(this.buildCMViewPlugin(this.app, this.settings)); @@ -120,7 +122,7 @@ export default class SuperchargedLinks extends Plugin { observer.disconnect(); }); plugin.registerViewType('backlink', plugin, ".tree-item-inner", true); - plugin.registerViewType('outgoing-link', plugin, ".tree-item-inner"); + plugin.registerViewType('outgoing-link', plugin, ".tree-item-inner", true); plugin.registerViewType('search', plugin, ".tree-item-inner"); plugin.registerViewType('BC-matrix', plugin, '.BC-Link'); plugin.registerViewType('BC-ducks', plugin, '.internal-link'); @@ -167,7 +169,7 @@ export default class SuperchargedLinks extends Plugin { _watchContainer(viewType: string, container: HTMLElement, plugin: SuperchargedLinks, selector: string) { let observer = new MutationObserver((records, _) => { - plugin.updateContainer(container, plugin, selector); + plugin.updateContainer(container, plugin, selector); }); observer.observe(container, { subtree: true, childList: true, attributes: false }); plugin.observers.push([observer, viewType, selector]); diff --git a/manifest.json b/manifest.json index 40e885a..db0f499 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "supercharged-links-obsidian", "name": "Supercharged Links", - "version": "0.4.6", + "version": "0.4.7", "minAppVersion": "0.12.7", "description": "Adds properties and menu options to internal links", "author": "mdelobelle",