mirror of
https://codeberg.org/timelimit/timelimit-server.git
synced 2026-08-31 19:03:45 +02:00
Extend transaction usage
This commit is contained in:
@@ -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: {
|
||||
|
||||
Reference in New Issue
Block a user