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:
parent
75e12406e2
commit
28dfb44b14
8 changed files with 56 additions and 45 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue