mirror of
https://codeberg.org/timelimit/timelimit-server.git
synced 2025-10-04 10:19:26 +02:00
Extend transaction usage
This commit is contained in:
parent
62f4e368a6
commit
abc2102da5
47 changed files with 1367 additions and 860 deletions
|
@ -25,7 +25,7 @@ import { generateVersionId } from '../../../util/token'
|
|||
export class Cache {
|
||||
readonly familyId: string
|
||||
readonly hasFullVersion: boolean
|
||||
readonly transaction: Sequelize.Transaction
|
||||
transaction: Sequelize.Transaction
|
||||
readonly database: Database
|
||||
readonly connectedDevicesManager: VisibleConnectedDevicesManager
|
||||
private shouldTriggerFullSync = false
|
||||
|
@ -56,6 +56,22 @@ export class Cache {
|
|||
this.connectedDevicesManager = connectedDevicesManager
|
||||
}
|
||||
|
||||
async subtransaction<T> (callback: () => Promise<T>): Promise<T> {
|
||||
const oldTransaction = this.transaction
|
||||
|
||||
return this.database.transaction(async (newTransaction) => {
|
||||
try {
|
||||
this.transaction = newTransaction
|
||||
|
||||
const result = await callback()
|
||||
|
||||
return result
|
||||
} finally {
|
||||
this.transaction = oldTransaction
|
||||
}
|
||||
}, { transaction: oldTransaction })
|
||||
}
|
||||
|
||||
getSecondPasswordHashOfParent = memoize(async (parentId: string) => {
|
||||
const userEntryUnsafe = await this.database.user.findOne({
|
||||
where: {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue