mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
store in CLS only entity change IDs instead of whole records
This commit is contained in:
parent
0448883782
commit
2b017a956e
@ -43,7 +43,7 @@ async function importToBranch(req) {
|
|||||||
cls.disableEntityEvents();
|
cls.disableEntityEvents();
|
||||||
|
|
||||||
// eliminate flickering during import
|
// eliminate flickering during import
|
||||||
cls.ignoreEntityChanges();
|
cls.ignoreEntityChangeIds();
|
||||||
|
|
||||||
let note; // typically root of the import - client can show it after finishing the import
|
let note; // typically root of the import - client can show it after finishing the import
|
||||||
|
|
||||||
|
@ -44,36 +44,37 @@ function isEntityEventsDisabled() {
|
|||||||
return !!namespace.get('disableEntityEvents');
|
return !!namespace.get('disableEntityEvents');
|
||||||
}
|
}
|
||||||
|
|
||||||
function clearEntityChanges() {
|
function clearEntityChangeIds() {
|
||||||
namespace.set('entityChanges', []);
|
namespace.set('entityChangeIds', []);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAndClearEntityChanges() {
|
function getAndClearEntityChangeIds() {
|
||||||
const entityChanges = namespace.get('entityChanges') || [];
|
const entityChangeIds = namespace.get('entityChangeIds') || [];
|
||||||
|
|
||||||
clearEntityChanges();
|
clearEntityChangeIds();
|
||||||
|
|
||||||
return entityChanges;
|
return entityChangeIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
function addEntityChange(entityChange) {
|
function addEntityChange(entityChange) {
|
||||||
if (namespace.get('ignoreEntityChanges')) {
|
if (namespace.get('ignoreEntityChangeIds')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const entityChanges = namespace.get('entityChanges') || [];
|
const entityChangeIds = namespace.get('entityChangeIds') || [];
|
||||||
|
|
||||||
entityChanges.push(entityChange);
|
// store only ID since the record can be modified (e.g. in erase)
|
||||||
|
entityChangeIds.push(entityChange.id);
|
||||||
|
|
||||||
namespace.set('entityChanges', entityChanges);
|
namespace.set('entityChangeIds', entityChangeIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
function reset() {
|
function reset() {
|
||||||
clsHooked.reset();
|
clsHooked.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
function ignoreEntityChanges() {
|
function ignoreEntityChangeIds() {
|
||||||
namespace.set('ignoreEntityChanges', true);
|
namespace.set('ignoreEntityChangeIds', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
@ -88,8 +89,8 @@ module.exports = {
|
|||||||
disableEntityEvents,
|
disableEntityEvents,
|
||||||
isEntityEventsDisabled,
|
isEntityEventsDisabled,
|
||||||
reset,
|
reset,
|
||||||
clearEntityChanges,
|
clearEntityChangeIds,
|
||||||
getAndClearEntityChanges,
|
getAndClearEntityChangeIds,
|
||||||
addEntityChange,
|
addEntityChange,
|
||||||
ignoreEntityChanges
|
ignoreEntityChangeIds
|
||||||
};
|
};
|
||||||
|
@ -248,7 +248,7 @@ function transactional(func) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
const entityChanges = cls.getAndClearEntityChanges();
|
const entityChanges = cls.getAndClearEntityChangeIds();
|
||||||
|
|
||||||
if (entityChanges.length > 0) {
|
if (entityChanges.length > 0) {
|
||||||
log.info("Transaction rollback dirtied the becca, forcing reload.");
|
log.info("Transaction rollback dirtied the becca, forcing reload.");
|
||||||
|
@ -134,7 +134,13 @@ function fillInAdditionalProperties(entityChange) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendPing(client, entityChanges = []) {
|
function sendPing(client, entityChangeIds = []) {
|
||||||
|
if (entityChangeIds.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const entityChanges = sql.getManyRows(`SELECT * FROM entity_changes WHERE id IN (???)`, entityChangeIds);
|
||||||
|
|
||||||
for (const entityChange of entityChanges) {
|
for (const entityChange of entityChanges) {
|
||||||
try {
|
try {
|
||||||
fillInAdditionalProperties(entityChange);
|
fillInAdditionalProperties(entityChange);
|
||||||
@ -156,9 +162,9 @@ function sendPing(client, entityChanges = []) {
|
|||||||
|
|
||||||
function sendTransactionEntityChangesToAllClients() {
|
function sendTransactionEntityChangesToAllClients() {
|
||||||
if (webSocketServer) {
|
if (webSocketServer) {
|
||||||
const entityChanges = cls.getAndClearEntityChanges();
|
const entityChangeIds = cls.getAndClearEntityChangeIds();
|
||||||
|
|
||||||
webSocketServer.clients.forEach(client => sendPing(client, entityChanges));
|
webSocketServer.clients.forEach(client => sendPing(client, entityChangeIds));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,10 +18,10 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="checkbox">
|
<div class="checkbox">
|
||||||
<label data-toggle="tooltip" title="Normal (soft) deletion only marks the notes as deleted and they can be undeleted (in recent changes dialog) within a period of time. Checking this option will erase the notes immediatelly and it won't be possible to undelete the notes.">
|
<label title="Normal (soft) deletion only marks the notes as deleted and they can be undeleted (in recent changes dialog) within a period of time. Checking this option will erase the notes immediatelly and it won't be possible to undelete the notes.">
|
||||||
<input id="erase-notes" value="1" type="checkbox">
|
<input id="erase-notes" value="1" type="checkbox">
|
||||||
|
|
||||||
erase notes permanently (can't be undone)
|
erase notes permanently (can't be undone). This will force application reload.
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user