mirror of
https://github.com/zadam/trilium.git
synced 2025-02-24 23:13:43 +08:00
make sure the CLS entity changes are cleared after roll backed transaction, #1736
This commit is contained in:
parent
9fd26a9b9f
commit
88d04772c4
3 changed files with 19 additions and 10 deletions
|
@ -44,10 +44,14 @@ function isEntityEventsDisabled() {
|
|||
return !!namespace.get('disableEntityEvents');
|
||||
}
|
||||
|
||||
function clearEntityChanges() {
|
||||
namespace.set('entityChanges', []);
|
||||
}
|
||||
|
||||
function getAndClearEntityChanges() {
|
||||
const entityChanges = namespace.get('entityChanges') || [];
|
||||
|
||||
namespace.set('entityChanges', []);
|
||||
clearEntityChanges();
|
||||
|
||||
return entityChanges;
|
||||
}
|
||||
|
@ -92,6 +96,7 @@ module.exports = {
|
|||
disableEntityEvents,
|
||||
isEntityEventsDisabled,
|
||||
reset,
|
||||
clearEntityChanges,
|
||||
getAndClearEntityChanges,
|
||||
addEntityChange,
|
||||
getEntityFromCache,
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
const log = require('./log');
|
||||
const Database = require('better-sqlite3');
|
||||
const dataDir = require('./data_dir');
|
||||
const cls = require('./cls');
|
||||
|
||||
const dbConnection = new Database(dataDir.DOCUMENT_PATH);
|
||||
dbConnection.pragma('journal_mode = WAL');
|
||||
|
@ -229,6 +230,7 @@ function wrap(query, func) {
|
|||
}
|
||||
|
||||
function transactional(func) {
|
||||
try {
|
||||
const ret = dbConnection.transaction(func).deferred();
|
||||
|
||||
if (!dbConnection.inTransaction) { // i.e. transaction was really committed (and not just savepoint released)
|
||||
|
@ -236,6 +238,12 @@ function transactional(func) {
|
|||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
catch (e) {
|
||||
cls.clearEntityChanges();
|
||||
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
function fillNoteIdList(noteIds, truncate = true) {
|
||||
|
|
|
@ -106,8 +106,6 @@ function sendPing(client, entityChanges = []) {
|
|||
}
|
||||
}
|
||||
|
||||
const stats = require('./sync').stats;
|
||||
|
||||
sendMessage(client, {
|
||||
type: 'sync',
|
||||
data: entityChanges
|
||||
|
@ -118,9 +116,7 @@ function sendTransactionSyncsToAllClients() {
|
|||
if (webSocketServer) {
|
||||
const entityChanges = cls.getAndClearEntityChanges();
|
||||
|
||||
webSocketServer.clients.forEach(function each(client) {
|
||||
sendPing(client, entityChanges);
|
||||
});
|
||||
webSocketServer.clients.forEach(client => sendPing(client, entityChanges));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue