From dbfbcc12ee071a1446f090832d6a40bd54f9625c Mon Sep 17 00:00:00 2001 From: Vyacheslav Tumanov Date: Tue, 27 Jun 2023 08:41:17 +0500 Subject: [PATCH] UBER-472: don't update when it's not needed (#3460) Signed-off-by: Vyacheslav Tumanov --- .../src/components/Inbox.svelte | 8 +++++--- plugins/notification-resources/src/utils.ts | 12 ++++++++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/plugins/notification-resources/src/components/Inbox.svelte b/plugins/notification-resources/src/components/Inbox.svelte index 0d4418790c..19a2953658 100644 --- a/plugins/notification-resources/src/components/Inbox.svelte +++ b/plugins/notification-resources/src/components/Inbox.svelte @@ -59,9 +59,11 @@ return } if (prevValue !== undefined) { - prevValue.txes.forEach((p) => (p.isNew = false)) - const txes = prevValue.txes - await client.update(prevValue, { txes }) + if (prevValue.txes.some((p) => p.isNew)) { + prevValue.txes.forEach((p) => (p.isNew = false)) + const txes = prevValue.txes + await client.update(prevValue, { txes }) + } } const targetClass = hierarchy.getClass(value.attachedToClass) const panelComponent = hierarchy.as(targetClass, view.mixin.ObjectPanel) diff --git a/plugins/notification-resources/src/utils.ts b/plugins/notification-resources/src/utils.ts index fbf0379a03..62b0f24814 100644 --- a/plugins/notification-resources/src/utils.ts +++ b/plugins/notification-resources/src/utils.ts @@ -62,8 +62,10 @@ export class NotificationClientImpl implements NotificationClient { const client = getClient() const docUpdate = this.docUpdatesMap.get(_id) if (docUpdate !== undefined) { - docUpdate.txes.forEach((p) => (p.isNew = false)) - await client.update(docUpdate, { txes: docUpdate.txes }) + if (docUpdate.txes.some((p) => p.isNew)) { + docUpdate.txes.forEach((p) => (p.isNew = false)) + await client.update(docUpdate, { txes: docUpdate.txes }) + } } } @@ -71,8 +73,10 @@ export class NotificationClientImpl implements NotificationClient { const client = getClient() const docUpdate = this.docUpdatesMap.get(_id) if (docUpdate !== undefined) { - docUpdate.txes.forEach((p) => (p.isNew = false)) - await client.update(docUpdate, { txes: docUpdate.txes }) + if (docUpdate.txes.some((p) => p.isNew)) { + docUpdate.txes.forEach((p) => (p.isNew = false)) + await client.update(docUpdate, { txes: docUpdate.txes }) + } } else { const doc = await client.findOne(_class, { _id }) if (doc !== undefined) {