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

Try to speed up AP update transaction

This commit is contained in:
Chocobozzz 2021-06-08 17:29:45 +02:00
parent 75e12406e2
commit 28dfb44b14
No known key found for this signature in database
GPG key ID: 583A612D890159BE
8 changed files with 56 additions and 45 deletions

View file

@ -58,7 +58,7 @@ function transactionRetryer <T> (func: (err: any, data: T) => any) {
errorFilter: err => {
const willRetry = (err.name === 'SequelizeDatabaseError')
logger.debug('Maybe retrying the transaction function.', { willRetry, err })
logger.debug('Maybe retrying the transaction function.', { willRetry, err, tags: [ 'sql', 'retry' ] })
return willRetry
}
},
@ -68,6 +68,8 @@ function transactionRetryer <T> (func: (err: any, data: T) => any) {
})
}
// ---------------------------------------------------------------------------
function updateInstanceWithAnother <M, T extends U, U extends Model<M>> (instanceToUpdate: T, baseInstance: U) {
const obj = baseInstance.toJSON()
@ -82,12 +84,6 @@ function resetSequelizeInstance (instance: Model<any>, savedFields: object) {
})
}
function afterCommitIfTransaction (t: Transaction, fn: Function) {
if (t) return t.afterCommit(() => fn())
return fn()
}
function deleteNonExistingModels <T extends { hasSameUniqueKeysThan (other: T): boolean } & Pick<Model, 'destroy'>> (
fromDatabase: T[],
newModels: T[],
@ -111,6 +107,18 @@ function setAsUpdated (table: string, id: number, transaction?: Transaction) {
// ---------------------------------------------------------------------------
function runInReadCommittedTransaction <T> (fn: (t: Transaction) => Promise<T>) {
return sequelizeTypescript.transaction(t => fn(t))
}
function afterCommitIfTransaction (t: Transaction, fn: Function) {
if (t) return t.afterCommit(() => fn())
return fn()
}
// ---------------------------------------------------------------------------
export {
resetSequelizeInstance,
retryTransactionWrapper,
@ -118,5 +126,6 @@ export {
updateInstanceWithAnother,
afterCommitIfTransaction,
deleteNonExistingModels,
setAsUpdated
setAsUpdated,
runInReadCommittedTransaction
}