From 5bda1736e179312b96ff1d5e661cec748063dd85 Mon Sep 17 00:00:00 2001 From: NicolasCantu Date: Fri, 28 Feb 2025 18:25:43 +0100 Subject: [PATCH] Don't send process-updated event for process unchanged --- src/services/service.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/services/service.ts b/src/services/service.ts index 851eb9a..9ea0b69 100755 --- a/src/services/service.ts +++ b/src/services/service.ts @@ -1117,10 +1117,18 @@ export default class Services { for (const [processId, process] of Object.entries(newProcesses)) { const existing = await this.getProcess(processId); if (existing) { - const event = new CustomEvent('process-updated', { - detail: { processId } - }); - window.dispatchEvent(event); + const lastKnownCommitment = this.getLastCommitedState(existing); + const newLastCommitment = this.getLastCommitedState(process); + if (!lastKnownCommitment || !newLastCommitment) { continue } + if (lastKnownCommitment.commited_in !== newLastCommitment.commited_in) { + console.log('Dispatching process-updated event'); + const event = new CustomEvent('process-updated', { + detail: { processId } + }); + window.dispatchEvent(event); + } + + // Otherwise we're probably just in the initial loading at page initialization // We may learn an update for this process // TODO maybe actually check if what the relay is sending us contains more information than what we have