mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +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 opmlImportService = require('../../services/import/opml');
|
||||||
const tarImportService = require('../../services/import/tar');
|
const tarImportService = require('../../services/import/tar');
|
||||||
const markdownImportService = require('../../services/import/markdown');
|
const markdownImportService = require('../../services/import/markdown');
|
||||||
|
const cls = require('../../services/cls');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
async function importToBranch(req) {
|
async function importToBranch(req) {
|
||||||
@ -23,6 +24,10 @@ async function importToBranch(req) {
|
|||||||
|
|
||||||
const extension = path.extname(file.originalname).toLowerCase();
|
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') {
|
if (extension === '.tar') {
|
||||||
return await tarImportService.importTar(file.buffer, parentNote);
|
return await tarImportService.importTar(file.buffer, parentNote);
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,14 @@ function getSourceId() {
|
|||||||
return namespace.get('sourceId');
|
return namespace.get('sourceId');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function disableEntityEvents() {
|
||||||
|
namespace.set('disableEntityEvents', true);
|
||||||
|
}
|
||||||
|
|
||||||
|
function isEntityEventsDisabled() {
|
||||||
|
return !!namespace.get('disableEntityEvents');
|
||||||
|
}
|
||||||
|
|
||||||
function reset() {
|
function reset() {
|
||||||
clsHooked.reset();
|
clsHooked.reset();
|
||||||
}
|
}
|
||||||
@ -22,5 +30,7 @@ module.exports = {
|
|||||||
wrap,
|
wrap,
|
||||||
namespace,
|
namespace,
|
||||||
getSourceId,
|
getSourceId,
|
||||||
|
disableEntityEvents,
|
||||||
|
isEntityEventsDisabled,
|
||||||
reset
|
reset
|
||||||
};
|
};
|
@ -3,6 +3,7 @@
|
|||||||
const sql = require('./sql');
|
const sql = require('./sql');
|
||||||
const syncTableService = require('../services/sync_table');
|
const syncTableService = require('../services/sync_table');
|
||||||
const eventService = require('./events');
|
const eventService = require('./events');
|
||||||
|
const cls = require('./cls');
|
||||||
|
|
||||||
let entityConstructor;
|
let entityConstructor;
|
||||||
|
|
||||||
@ -93,7 +94,10 @@ async function updateEntity(entity) {
|
|||||||
|
|
||||||
const primaryKey = entity[primaryKeyName];
|
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);
|
await syncTableService.addEntitySync(entityName, primaryKey);
|
||||||
|
|
||||||
const eventPayload = {
|
const eventPayload = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user