From 958599ed0900d83fa0fb4ca5ce4ca7664181856f Mon Sep 17 00:00:00 2001 From: Abdo Date: Sun, 27 Jul 2025 18:43:32 +0300 Subject: [PATCH] Debounce loadNote() calls --- ts/routes/editor/NoteEditor.svelte | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/ts/routes/editor/NoteEditor.svelte b/ts/routes/editor/NoteEditor.svelte index 7aa26eff4..b75ef4f0c 100644 --- a/ts/routes/editor/NoteEditor.svelte +++ b/ts/routes/editor/NoteEditor.svelte @@ -89,7 +89,9 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html import RichTextInput, { editingInputIsRichText } from "./rich-text-input"; import RichTextBadge from "./RichTextBadge.svelte"; import type { HistoryEntry, NotetypeIdAndModTime, SessionOptions } from "./types"; + import { CooldownTimer } from "$lib/editable/cooldown-timer"; + const loadDebouncer = new CooldownTimer(200); let contextMenu: ContextMenu; const [onContextMenu, contextMenuItems] = setupContextMenu(); let contextMenuInput: EditingInputAPI | null = null; @@ -897,12 +899,12 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html }); } - async function loadNote( + async function loadNoteInner( nid: bigint | null, notetypeId: bigint, focusTo: number, originalNoteId: bigint | null, - ): Promise { + ) { const notetype = await getNotetype({ ntid: notetypeId, }); @@ -1003,8 +1005,17 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html } await updateDuplicateDisplay(); triggerChanges(); + } - return note!.id; + async function loadNote( + nid: bigint | null, + notetypeId: bigint, + focusTo: number, + originalNoteId: bigint | null, + ) { + loadDebouncer.schedule(async () => { + await loadNoteInner(nid, notetypeId, focusTo, originalNoteId); + }); } async function reloadNote() {