1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-04 02:09:37 +02:00

Update channel updatedAt when uploading a video

This commit is contained in:
Chocobozzz 2021-05-07 17:14:39 +02:00
parent 1e0741d165
commit e024fd6a74
No known key found for this signature in database
GPG key ID: 583A612D890159BE
12 changed files with 95 additions and 38 deletions

View file

@ -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 <T, A, B, C, D> (
functionToRetry: (arg1: A, arg2: B, arg3: C, arg4: D) => Promise<T> | Bluebird<T>,
@ -96,6 +97,18 @@ function deleteNonExistingModels <T extends { hasSameUniqueKeysThan (other: T):
.map(f => 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
}