diff --git a/src/routes/api/import.js b/src/routes/api/import.js index fb45c891f..02c8ebd5c 100644 --- a/src/routes/api/import.js +++ b/src/routes/api/import.js @@ -5,6 +5,7 @@ const enexImportService = require('../../services/import/enex'); const opmlImportService = require('../../services/import/opml'); const tarImportService = require('../../services/import/tar'); const markdownImportService = require('../../services/import/markdown'); +const cls = require('../../services/cls'); const path = require('path'); async function importToBranch(req) { @@ -23,6 +24,10 @@ async function importToBranch(req) { const extension = path.extname(file.originalname).toLowerCase(); + // running all the event handlers on imported notes (and attributes) is slow + // and may produce unintended consequences + cls.disableEntityEvents(); + if (extension === '.tar') { return await tarImportService.importTar(file.buffer, parentNote); } diff --git a/src/services/cls.js b/src/services/cls.js index 04859fa51..387fb7bc5 100644 --- a/src/services/cls.js +++ b/src/services/cls.js @@ -13,6 +13,14 @@ function getSourceId() { return namespace.get('sourceId'); } +function disableEntityEvents() { + namespace.set('disableEntityEvents', true); +} + +function isEntityEventsDisabled() { + return !!namespace.get('disableEntityEvents'); +} + function reset() { clsHooked.reset(); } @@ -22,5 +30,7 @@ module.exports = { wrap, namespace, getSourceId, + disableEntityEvents, + isEntityEventsDisabled, reset }; \ No newline at end of file diff --git a/src/services/repository.js b/src/services/repository.js index 26d700463..453659619 100644 --- a/src/services/repository.js +++ b/src/services/repository.js @@ -3,6 +3,7 @@ const sql = require('./sql'); const syncTableService = require('../services/sync_table'); const eventService = require('./events'); +const cls = require('./cls'); let entityConstructor; @@ -93,7 +94,10 @@ async function updateEntity(entity) { const primaryKey = entity[primaryKeyName]; - if (entity.isChanged && (entityName !== 'options' || entity.isSynced)) { + if (!cls.isEntityEventsDisabled() + && entity.isChanged + && (entityName !== 'options' || entity.isSynced)) { + await syncTableService.addEntitySync(entityName, primaryKey); const eventPayload = {