1
0
Fork 0
peertube/server/models/shared/update.ts
Chocobozzz 0c9668f779 Implement remote runner jobs in server
Move ffmpeg functions to @shared
2023-05-09 08:57:34 +02:00

34 lines
749 B
TypeScript

import { QueryTypes, Sequelize, Transaction } from 'sequelize'
const updating = new Set<string>()
// Sequelize always skip the update if we only update updatedAt field
async function setAsUpdated (options: {
sequelize: Sequelize
table: string
id: number
transaction?: Transaction
}) {
const { sequelize, table, id, transaction } = options
const key = table + '-' + id
if (updating.has(key)) return
updating.add(key)
try {
await sequelize.query(
`UPDATE "${table}" SET "updatedAt" = :updatedAt WHERE id = :id`,
{
replacements: { table, id, updatedAt: new Date() },
type: QueryTypes.UPDATE,
transaction
}
)
} finally {
updating.delete(key)
}
}
export {
setAsUpdated
}