From 55a7ee1f910064e1af24e2fe7eb188a6fa5b7392 Mon Sep 17 00:00:00 2001 From: ehhc Date: Fri, 5 Jul 2019 15:51:37 +0200 Subject: [PATCH] Debounce deletion of un-referenced attachments --> don't fixes but mitigates the problems of #3103 --- browser/components/CodeEditor.js | 8 ++------ browser/main/lib/dataApi/attachmentManagement.js | 3 +-- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/browser/components/CodeEditor.js b/browser/components/CodeEditor.js index 2d08aa04..72ecbf23 100644 --- a/browser/components/CodeEditor.js +++ b/browser/components/CodeEditor.js @@ -53,6 +53,7 @@ export default class CodeEditor extends React.Component { this.focusHandler = () => { ipcRenderer.send('editor:focused', true) } + const debouncedDeletionOfAttachments = _.debounce(attachmentManagement.deleteAttachmentsNotPresentInNote, 30000) this.blurHandler = (editor, e) => { ipcRenderer.send('editor:focused', false) if (e == null) return null @@ -64,16 +65,11 @@ export default class CodeEditor extends React.Component { el = el.parentNode } this.props.onBlur != null && this.props.onBlur(e) - const { storageKey, noteKey } = this.props - attachmentManagement.deleteAttachmentsNotPresentInNote( - this.editor.getValue(), - storageKey, - noteKey - ) + debouncedDeletionOfAttachments(this.editor.getValue(), storageKey, noteKey) } this.pasteHandler = (editor, e) => { e.preventDefault() diff --git a/browser/main/lib/dataApi/attachmentManagement.js b/browser/main/lib/dataApi/attachmentManagement.js index d92a1eb4..309d8d5a 100644 --- a/browser/main/lib/dataApi/attachmentManagement.js +++ b/browser/main/lib/dataApi/attachmentManagement.js @@ -584,6 +584,7 @@ function deleteAttachmentFolder (storageKey, noteKey) { * @param noteKey NoteKey of the current note. Is used to determine the belonging attachment folder. */ function deleteAttachmentsNotPresentInNote (markdownContent, storageKey, noteKey) { + console.log('deleteAtt') if (storageKey == null || noteKey == null || markdownContent == null) { return } @@ -617,8 +618,6 @@ function deleteAttachmentsNotPresentInNote (markdownContent, storageKey, noteKey } }) }) - } else { - console.info('Attachment folder ("' + attachmentFolder + '") did not exist..') } }