X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fdatabase-utils.ts;h=f9cb33acafbb4729b4b997e603e9e5805ad4c9a4;hb=1bcb03a100d172903b877d6a0e4ed11d63b14f3d;hp=87f10f913ca37f3512ce5b139f55065485afceb1;hpb=d7a25329f9e607894d29ab342b9cb66638b56dc0;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/database-utils.ts b/server/helpers/database-utils.ts index 87f10f913..f9cb33aca 100644 --- a/server/helpers/database-utils.ts +++ b/server/helpers/database-utils.ts @@ -1,8 +1,17 @@ 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, + arg1: A, + arg2: B, + arg3: C, + arg4: D, +): Promise function retryTransactionWrapper ( functionToRetry: (arg1: A, arg2: B, arg3: C) => Promise | Bluebird, @@ -88,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 { @@ -96,5 +117,6 @@ export { transactionRetryer, updateInstanceWithAnother, afterCommitIfTransaction, - deleteNonExistingModels + deleteNonExistingModels, + setAsUpdated }