entity events are not triggered on imported entities

This commit is contained in:
azivner 2018-11-26 22:27:57 +01:00
parent 56e2b44c25
commit b3aa0ba47c
3 changed files with 20 additions and 1 deletions

View File

@ -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);
}

View File

@ -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
};

View File

@ -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 = {