diff --git a/src/lib/components/workspace/Knowledge/KnowledgeBase.svelte b/src/lib/components/workspace/Knowledge/KnowledgeBase.svelte index 5608ff0b74..179f9cfdfa 100644 --- a/src/lib/components/workspace/Knowledge/KnowledgeBase.svelte +++ b/src/lib/components/workspace/Knowledge/KnowledgeBase.svelte @@ -115,6 +115,7 @@ let debounceTimeout = null; let mediaQuery; let dragged = false; + let isSaving = false; const createFileFromText = (name, content) => { const blob = new Blob([content], { type: 'text/plain' }); @@ -434,27 +435,34 @@ }; const updateFileContentHandler = async () => { - const fileId = selectedFile.id; - const content = selectedFileContent; - - // Clear the cache for this file since we're updating it - fileContentCache.delete(fileId); - - const res = updateFileDataContentById(localStorage.token, fileId, content).catch((e) => { - toast.error(`${e}`); - }); - - const updatedKnowledge = await updateFileFromKnowledgeById( - localStorage.token, - id, - fileId - ).catch((e) => { - toast.error(`${e}`); - }); - - if (res && updatedKnowledge) { - knowledge = updatedKnowledge; - toast.success($i18n.t('File content updated successfully.')); + if (isSaving) { + console.log('Save operation already in progress, skipping...'); + return; + } + isSaving = true; + try { + const fileId = selectedFile.id; + const content = selectedFileContent; + // Clear the cache for this file since we're updating it + fileContentCache.delete(fileId); + const res = await updateFileDataContentById(localStorage.token, fileId, content).catch( + (e) => { + toast.error(`${e}`); + } + ); + const updatedKnowledge = await updateFileFromKnowledgeById( + localStorage.token, + id, + fileId + ).catch((e) => { + toast.error(`${e}`); + }); + if (res && updatedKnowledge) { + knowledge = updatedKnowledge; + toast.success($i18n.t('File content updated successfully.')); + } + } finally { + isSaving = false; } }; @@ -779,12 +787,13 @@
@@ -836,12 +845,13 @@