fix: zapping too fast causes duplicate notifications (#1812)

* fix: zapping too fast causes duplicate notifications

* add comment

---------

Co-authored-by: Keyan <34140557+huumn@users.noreply.github.com>
This commit is contained in:
soxa 2025-01-08 19:51:07 +01:00 committed by GitHub
parent 44d3748d5f
commit 466620ff05
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 11 additions and 1 deletions

View File

@ -206,7 +206,17 @@ export async function nonCriticalSideEffects ({ invoice, actIds }, { models }) {
where: invoice ? { invoiceId: invoice.id } : { id: { in: actIds } },
include: { item: true }
})
notifyZapped({ models, item: itemAct.item }).catch(console.error)
// avoid duplicate notifications with the same zap amount
// by checking if there are any other pending acts on the item
const pendingActs = await models.itemAct.count({
where: {
itemId: itemAct.itemId,
createdAt: {
gt: itemAct.createdAt
}
}
})
if (pendingActs === 0) notifyZapped({ models, item: itemAct.item }).catch(console.error)
}
export async function onFail ({ invoice }, { tx }) {