aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/database-utils.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-05-07 17:14:39 +0200
committerChocobozzz <me@florianbigard.com>2021-05-10 09:38:11 +0200
commite024fd6a7494b37251da1d59470324305cdb4129 (patch)
treee39b8c4b1bd8ba38936f0657e485358fc10b9050 /server/helpers/database-utils.ts
parent1e0741d16545ea720d04b566a808853b3975ea7f (diff)
downloadPeerTube-e024fd6a7494b37251da1d59470324305cdb4129.tar.gz
PeerTube-e024fd6a7494b37251da1d59470324305cdb4129.tar.zst
PeerTube-e024fd6a7494b37251da1d59470324305cdb4129.zip
Update channel updatedAt when uploading a video
Diffstat (limited to 'server/helpers/database-utils.ts')
-rw-r--r--server/helpers/database-utils.ts18
1 files changed, 16 insertions, 2 deletions
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 @@
1import * as retry from 'async/retry' 1import * as retry from 'async/retry'
2import * as Bluebird from 'bluebird' 2import * as Bluebird from 'bluebird'
3import { QueryTypes, Transaction } from 'sequelize'
3import { Model } from 'sequelize-typescript' 4import { Model } from 'sequelize-typescript'
5import { sequelizeTypescript } from '@server/initializers/database'
4import { logger } from './logger' 6import { logger } from './logger'
5import { Transaction } from 'sequelize'
6 7
7function retryTransactionWrapper <T, A, B, C, D> ( 8function retryTransactionWrapper <T, A, B, C, D> (
8 functionToRetry: (arg1: A, arg2: B, arg3: C, arg4: D) => Promise<T> | Bluebird<T>, 9 functionToRetry: (arg1: A, arg2: B, arg3: C, arg4: D) => Promise<T> | Bluebird<T>,
@@ -96,6 +97,18 @@ function deleteNonExistingModels <T extends { hasSameUniqueKeysThan (other: T):
96 .map(f => f.destroy({ transaction: t })) 97 .map(f => f.destroy({ transaction: t }))
97} 98}
98 99
100// Sequelize always skip the update if we only update updatedAt field
101function setAsUpdated (table: string, id: number, transaction?: Transaction) {
102 return sequelizeTypescript.query(
103 `UPDATE "${table}" SET "updatedAt" = :updatedAt WHERE id = :id`,
104 {
105 replacements: { table, id, updatedAt: new Date() },
106 type: QueryTypes.UPDATE,
107 transaction
108 }
109 )
110}
111
99// --------------------------------------------------------------------------- 112// ---------------------------------------------------------------------------
100 113
101export { 114export {
@@ -104,5 +117,6 @@ export {
104 transactionRetryer, 117 transactionRetryer,
105 updateInstanceWithAnother, 118 updateInstanceWithAnother,
106 afterCommitIfTransaction, 119 afterCommitIfTransaction,
107 deleteNonExistingModels 120 deleteNonExistingModels,
121 setAsUpdated
108} 122}