X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fdatabase-utils.ts;h=62738108607f650af0ca63b25de506f4fb4de03f;hb=91a4893063402d7beabb3104f9b989b8f88b6038;hp=422774022ac549168faca01afa2a3b247c373c5d;hpb=ac27887774e63d99f4e227fbe18846f143cc4b3c;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/database-utils.ts b/server/helpers/database-utils.ts index 422774022..627381086 100644 --- a/server/helpers/database-utils.ts +++ b/server/helpers/database-utils.ts @@ -1,6 +1,6 @@ -import * as retry from 'async/retry' -import * as Bluebird from 'bluebird' -import { BindOrReplacements, QueryTypes, Transaction } from 'sequelize' +import retry from 'async/retry' +import Bluebird from 'bluebird' +import { Transaction } from 'sequelize' import { Model } from 'sequelize-typescript' import { sequelizeTypescript } from '@server/initializers/database' import { logger } from './logger' @@ -45,7 +45,7 @@ function retryTransactionWrapper ( .catch(err => callback(err)) }) .catch(err => { - logger.error(`Cannot execute ${functionToRetry.name} with many retries.`, { err }) + logger.warn(`Cannot execute ${functionToRetry.name} with many retries.`, { err }) throw err }) } @@ -95,18 +95,6 @@ function deleteAllModels > (models: T[], transa return Promise.all(models.map(f => f.destroy({ transaction }))) } -// 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 - } - ) -} - // --------------------------------------------------------------------------- function runInReadCommittedTransaction (fn: (t: Transaction) => Promise) { @@ -123,19 +111,6 @@ function afterCommitIfTransaction (t: Transaction, fn: Function) { // --------------------------------------------------------------------------- -function doesExist (query: string, bind?: BindOrReplacements) { - const options = { - type: QueryTypes.SELECT as QueryTypes.SELECT, - bind, - raw: true - } - - return sequelizeTypescript.query(query, options) - .then(results => results.length === 1) -} - -// --------------------------------------------------------------------------- - export { resetSequelizeInstance, retryTransactionWrapper, @@ -144,7 +119,5 @@ export { afterCommitIfTransaction, filterNonExistingModels, deleteAllModels, - setAsUpdated, - runInReadCommittedTransaction, - doesExist + runInReadCommittedTransaction }