aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/shared/update.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/shared/update.ts')
-rw-r--r--server/models/shared/update.ts28
1 files changed, 19 insertions, 9 deletions
diff --git a/server/models/shared/update.ts b/server/models/shared/update.ts
index d02c4535d..96db43730 100644
--- a/server/models/shared/update.ts
+++ b/server/models/shared/update.ts
@@ -1,22 +1,32 @@
1import { QueryTypes, Sequelize, Transaction } from 'sequelize' 1import { QueryTypes, Sequelize, Transaction } from 'sequelize'
2 2
3const updating = new Set<string>()
4
3// Sequelize always skip the update if we only update updatedAt field 5// Sequelize always skip the update if we only update updatedAt field
4function setAsUpdated (options: { 6async function setAsUpdated (options: {
5 sequelize: Sequelize 7 sequelize: Sequelize
6 table: string 8 table: string
7 id: number 9 id: number
8 transaction?: Transaction 10 transaction?: Transaction
9}) { 11}) {
10 const { sequelize, table, id, transaction } = options 12 const { sequelize, table, id, transaction } = options
13 const key = table + '-' + id
14
15 if (updating.has(key)) return
16 updating.add(key)
11 17
12 return sequelize.query( 18 try {
13 `UPDATE "${table}" SET "updatedAt" = :updatedAt WHERE id = :id`, 19 await sequelize.query(
14 { 20 `UPDATE "${table}" SET "updatedAt" = :updatedAt WHERE id = :id`,
15 replacements: { table, id, updatedAt: new Date() }, 21 {
16 type: QueryTypes.UPDATE, 22 replacements: { table, id, updatedAt: new Date() },
17 transaction 23 type: QueryTypes.UPDATE,
18 } 24 transaction
19 ) 25 }
26 )
27 } finally {
28 updating.delete(key)
29 }
20} 30}
21 31
22export { 32export {