Skip to content

Commit

Permalink
fix: Performance much worse in latest version
Browse files Browse the repository at this point in the history
See #75
  • Loading branch information
HEmile committed Jan 21, 2022
1 parent 8ded121 commit 7976687
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 7 additions & 5 deletions main.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -45,15 +45,17 @@ 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);
leaves.forEach(leaf => {
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));
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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]);
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 7976687

Please sign in to comment.