store in CLS only entity change IDs instead of whole records

This commit is contained in:
zadam 2021-09-16 15:02:20 +02:00
parent 0448883782
commit 2b017a956e
5 changed files with 29 additions and 22 deletions

View File

@ -43,7 +43,7 @@ async function importToBranch(req) {
cls.disableEntityEvents();
// eliminate flickering during import
cls.ignoreEntityChanges();
cls.ignoreEntityChangeIds();
let note; // typically root of the import - client can show it after finishing the import

View File

@ -44,36 +44,37 @@ function isEntityEventsDisabled() {
return !!namespace.get('disableEntityEvents');
}
function clearEntityChanges() {
namespace.set('entityChanges', []);
function clearEntityChangeIds() {
namespace.set('entityChangeIds', []);
}
function getAndClearEntityChanges() {
const entityChanges = namespace.get('entityChanges') || [];
function getAndClearEntityChangeIds() {
const entityChangeIds = namespace.get('entityChangeIds') || [];
clearEntityChanges();
clearEntityChangeIds();
return entityChanges;
return entityChangeIds;
}
function addEntityChange(entityChange) {
if (namespace.get('ignoreEntityChanges')) {
if (namespace.get('ignoreEntityChangeIds')) {
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() {
clsHooked.reset();
}
function ignoreEntityChanges() {
namespace.set('ignoreEntityChanges', true);
function ignoreEntityChangeIds() {
namespace.set('ignoreEntityChangeIds', true);
}
module.exports = {
@ -88,8 +89,8 @@ module.exports = {
disableEntityEvents,
isEntityEventsDisabled,
reset,
clearEntityChanges,
getAndClearEntityChanges,
clearEntityChangeIds,
getAndClearEntityChangeIds,
addEntityChange,
ignoreEntityChanges
ignoreEntityChangeIds
};

View File

@ -248,7 +248,7 @@ function transactional(func) {
return ret;
}
catch (e) {
const entityChanges = cls.getAndClearEntityChanges();
const entityChanges = cls.getAndClearEntityChangeIds();
if (entityChanges.length > 0) {
log.info("Transaction rollback dirtied the becca, forcing reload.");

View File

@ -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) {
try {
fillInAdditionalProperties(entityChange);
@ -156,9 +162,9 @@ function sendPing(client, entityChanges = []) {
function sendTransactionEntityChangesToAllClients() {
if (webSocketServer) {
const entityChanges = cls.getAndClearEntityChanges();
const entityChangeIds = cls.getAndClearEntityChangeIds();
webSocketServer.clients.forEach(client => sendPing(client, entityChanges));
webSocketServer.clients.forEach(client => sendPing(client, entityChangeIds));
}
}

View File

@ -18,10 +18,10 @@
</div>
<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">
erase notes permanently (can't be undone)
erase notes permanently (can't be undone). This will force application reload.
</label>
</div>