From e024fd6a7494b37251da1d59470324305cdb4129 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 7 May 2021 17:14:39 +0200 Subject: Update channel updatedAt when uploading a video --- server/helpers/database-utils.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'server/helpers') diff --git a/server/helpers/database-utils.ts b/server/helpers/database-utils.ts index 2b916efc2..f9cb33aca 100644 --- a/server/helpers/database-utils.ts +++ b/server/helpers/database-utils.ts @@ -1,8 +1,9 @@ import * as retry from 'async/retry' import * as Bluebird from 'bluebird' +import { QueryTypes, Transaction } from 'sequelize' import { Model } from 'sequelize-typescript' +import { sequelizeTypescript } from '@server/initializers/database' import { logger } from './logger' -import { Transaction } from 'sequelize' function retryTransactionWrapper ( functionToRetry: (arg1: A, arg2: B, arg3: C, arg4: D) => Promise | Bluebird, @@ -96,6 +97,18 @@ function deleteNonExistingModels f.destroy({ transaction: t })) } +// Sequelize always skip the update if we only update updatedAt field +function setAsUpdated (table: string, id: number, transaction?: Transaction) { + return sequelizeTypescript.query( + `UPDATE "${table}" SET "updatedAt" = :updatedAt WHERE id = :id`, + { + replacements: { table, id, updatedAt: new Date() }, + type: QueryTypes.UPDATE, + transaction + } + ) +} + // --------------------------------------------------------------------------- export { @@ -104,5 +117,6 @@ export { transactionRetryer, updateInstanceWithAnother, afterCommitIfTransaction, - deleteNonExistingModels + deleteNonExistingModels, + setAsUpdated } -- cgit v1.2.3