From 44219e7ccccc852da151a90ab105a5ecf33134ac Mon Sep 17 00:00:00 2001 From: zadam Date: Fri, 13 Mar 2020 22:23:44 +0100 Subject: [PATCH 1/2] do not load the note content during ENEX import again since it's already available --- src/services/import/enex.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/services/import/enex.js b/src/services/import/enex.js index 070040a98..86f27b17d 100644 --- a/src/services/import/enex.js +++ b/src/services/import/enex.js @@ -235,8 +235,6 @@ async function importEnex(taskContext, file, parentNote) { taskContext.increaseProgressCount(); - let noteContent = await noteEntity.getContent(); - for (const resource of resources) { const hash = utils.md5(resource.content); @@ -268,7 +266,7 @@ async function importEnex(taskContext, file, parentNote) { const resourceLink = `${utils.escapeHtml(resource.title)}`; - noteContent = noteContent.replace(mediaRegex, resourceLink); + content = content.replace(mediaRegex, resourceLink); }; if (["image/jpeg", "image/png", "image/gif", "image/webp"].includes(resource.mime)) { @@ -281,12 +279,12 @@ async function importEnex(taskContext, file, parentNote) { const imageLink = ``; - noteContent = noteContent.replace(mediaRegex, imageLink); + content = content.replace(mediaRegex, imageLink); - if (!noteContent.includes(imageLink)) { + if (!content.includes(imageLink)) { // if there wasn't any match for the reference, we'll add the image anyway // otherwise image would be removed since no note would include it - noteContent += imageLink; + content += imageLink; } } catch (e) { log.error("error when saving image from ENEX file: " + e); @@ -298,7 +296,7 @@ async function importEnex(taskContext, file, parentNote) { } // save updated content with links to files/images - await noteEntity.setContent(noteContent); + await noteEntity.setContent(content); await noteService.scanForLinks(noteEntity.noteId); From 3fa3e912a4fe48c8cbae54d94d63e6741128afb0 Mon Sep 17 00:00:00 2001 From: zadam Date: Sat, 14 Mar 2020 12:39:55 +0100 Subject: [PATCH 2/2] not sending ping to clients after every sync addition, only after commit which significantly speeds up imports --- src/services/sql.js | 2 ++ src/services/sync_table.js | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/services/sql.js b/src/services/sql.js index 299729348..9e00168c5 100644 --- a/src/services/sql.js +++ b/src/services/sql.js @@ -209,6 +209,8 @@ async function transactional(func) { transactionActive = false; resolve(); + + setTimeout(() => require('./ws').sendPingToAllClients(), 50); } catch (e) { if (transactionActive) { diff --git a/src/services/sync_table.js b/src/services/sync_table.js index c96cf2ba0..4ed4abcff 100644 --- a/src/services/sync_table.js +++ b/src/services/sync_table.js @@ -24,8 +24,6 @@ async function addEntitySync(entityName, entityId, sourceId) { const sync = await insertEntitySync(entityName, entityId, sourceId); syncs.push(sync); - - setTimeout(() => require('./ws').sendPingToAllClients(), 50); } async function addEntitySyncsForSector(entityName, entityPrimaryKey, sector) {