Skip to content

Commit

Permalink
UBER-472: don't update when it's not needed (#3460)
Browse files Browse the repository at this point in the history
Signed-off-by: Vyacheslav Tumanov <me@slavatumanov.me>
  • Loading branch information
ThetaDR authored Jun 27, 2023
1 parent 70d78e5 commit dbfbcc1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
8 changes: 5 additions & 3 deletions plugins/notification-resources/src/components/Inbox.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 8 additions & 4 deletions plugins/notification-resources/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,21 @@ 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 })
}
}
}

async forceRead (_id: Ref<Doc>, _class: Ref<Class<Doc>>): Promise<void> {
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) {
Expand Down

0 comments on commit dbfbcc1

Please # to comment.