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