Skip to content

Commit

Permalink
Perf enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
TfT Hacker committed Sep 18, 2022
1 parent ec0aecf commit 6d5fb96
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 18 deletions.
2 changes: 0 additions & 2 deletions src/cm-extensions/gutters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ const ReferenceGutterExtension = gutter({
class: "snw-gutter-ref",
lineMarker(editorView: EditorView, line: BlockInfo) {

console.log("Gutter in use")

if(thePlugin.snwAPI.enableDebugging.GutterEmbedCounter)
thePlugin.snwAPI.console("ReferenceGutterExtension(EditorView, BlockInfo)", editorView, line )

Expand Down
2 changes: 0 additions & 2 deletions src/cm-extensions/references-cm6.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ class InlineReferenceWidget extends WidgetType {
*/
function calclulateInlineReferences(view: EditorView, theApp: App, mdView: MarkdownFileInfo) {

console.log("calculate")

if(thePlugin.snwAPI.enableDebugging?.CM6Extension)
thePlugin.snwAPI.console("calclulateInlineReferences(EditorView, theApp, MarkdownFileInfo", view,theApp,mdView);

Expand Down
2 changes: 0 additions & 2 deletions src/cm-extensions/references-preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import {TransformedCachedItem} from "../types";
*/
export default function markdownPreviewProcessor(el : HTMLElement, ctx : MarkdownPostProcessorContext, thePlugin : ThePlugin) {

console.log("processor")

if(thePlugin.snwAPI.enableDebugging.PreviewRendering)
thePlugin.snwAPI.console("markdownPreviewProcessor(HTMLElement, MarkdownPostProcessorContext", el, ctx, ctx.getSectionInfo(el))

Expand Down
1 change: 0 additions & 1 deletion src/htmlDecorations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export function htmlDecorationForReferencesElement(count: number, referenceType:
if(attachCSSClass) element.addClass(attachCSSClass);

element.onclick = async (e: MouseEvent ) => processHtmlDecorationReferenceEvent(e);
// element.onmouseover = async (e: MouseEvent ) => console.log("mouseover");

if(thePlugin?.snwAPI.enableDebugging?.HtmlDecorationElements)
thePlugin.snwAPI.console("returned element", element);
Expand Down
2 changes: 1 addition & 1 deletion src/indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export function getCurrentPage(file: TFile): TransformedCache {
if(cacheCurrentPages.has(file.path)) {
const cachedPage = cacheCurrentPages.get(file.path);
// Check if references have been updated since last cache update, and if cache is old
if( (lastUpdateToReferences < cachedPage.createDate) && ((cachedPage.createDate+5000) > Date.now()) ) {
if( (lastUpdateToReferences < cachedPage.createDate) && ((cachedPage.createDate+thePlugin.settings.cacheUpdateInMilliseconds) > Date.now()) ) {
return cachedPage;
}
}
Expand Down
20 changes: 12 additions & 8 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ export default class ThePlugin extends Plugin {

this.addSettingTab(new SettingsTab(this.app, this));

//initial index building
this.registerEvent(this.app.metadataCache.on("resolve", (file) => indexDebounce()));

// eslint-disable-next-line @typescript-eslint/no-explicit-any
(this.app.workspace as any).registerHoverLinkSource(this.appID, {
display: this.appName,
Expand All @@ -45,23 +48,24 @@ export default class ThePlugin extends Plugin {

this.snwAPI.settings = this.settings;

this.registerView(VIEW_TYPE_SNW, (leaf) => new SidePaneView(leaf, this));

this.app.workspace.on("layout-change", async () => {
setHeaderWithReferenceCounts(this);
});

if(this.settings.displayInlineReferences ) {
this.registerEditorExtension([InlineReferenceExtension]); // enable the codemirror extensions
this.markdownPostProcessorSNW = this.registerMarkdownPostProcessor((el, ctx) => markdownPreviewProcessor(el, ctx, this));
}

if(this.settings.displayEmbedReferencesInGutter){
this.registerEditorExtension(ReferenceGutterExtension );
this.registerEditorExtension(ReferenceGutterExtension);
}
this.registerView(VIEW_TYPE_SNW, (leaf) => new SidePaneView(leaf, this));
this.registerEvent(this.app.metadataCache.on("resolve", (file) => indexDebounce()));
this.app.workspace.on("layout-change", async () => {
setHeaderWithReferenceCounts(this);
});

const indexDebounce = debounce(() => {
buildLinksAndReferences()
}, 5000, true);

}, 1000, true);
}

// managing state for debugging purpsoes
Expand Down
22 changes: 20 additions & 2 deletions src/settingsTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ export interface Settings {
displayInlineReferences: boolean;
displayEmbedReferencesInGutter: boolean;
displayLineNumberInSidebar: boolean;
cacheUpdateInMilliseconds: number;
}

export const DEFAULT_SETTINGS: Settings = {
displayIncomingFilesheader: true,
displayInlineReferences: true,
displayEmbedReferencesInGutter: true,
displayLineNumberInSidebar: true
displayLineNumberInSidebar: true,
cacheUpdateInMilliseconds: 10000
}

export class SettingsTab extends PluginSettingTab {
Expand Down Expand Up @@ -75,7 +77,23 @@ export class SettingsTab extends PluginSettingTab {
this.thePlugin.settings.displayLineNumberInSidebar = value;
await this.thePlugin.saveSettings();
});
});
})

containerEl.createEl("h2", { text: "Cache Tuning" });

new Setting(containerEl)
.setName(`How often should the SNW Cache update`)
.setDesc(`By default SNW will updates its internal cache every 10 seconds (10,000 milliseconds) when there is some change in the vualt.
Increase the time to slighlty improve performance or decrease it to improve refresh of vault information.
Currently set to: ${this.thePlugin.settings.cacheUpdateInMilliseconds} milliseconds. (Requires Obsidian Restart)` )
.addSlider(slider => slider
.setLimits(500, 30000 , 100)
.setValue(this.thePlugin.settings.cacheUpdateInMilliseconds)
.onChange(async (value) => {
this.thePlugin.settings.cacheUpdateInMilliseconds = value;
await this.thePlugin.saveSettings();
})
.setDynamicTooltip()
)
}
}

0 comments on commit 6d5fb96

Please sign in to comment.