mirror of
https://github.com/zadam/trilium.git
synced 2025-06-05 17:38:47 +02:00
entity events are not triggered on imported entities
This commit is contained in:
parent
56e2b44c25
commit
b3aa0ba47c
@ -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);
|
||||
}
|
||||
|
@ -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
|
||||
};
|
@ -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 = {
|
||||
|
Loading…
x
Reference in New Issue
Block a user