Fix missing transactions

This commit is contained in:
Chocobozzz
2021-06-15 09:17:19 +02:00
parent 51f636ad0f
commit eae0365b5c
14 changed files with 65 additions and 69 deletions

View File

@@ -1,3 +1,4 @@
import { Transaction } from 'sequelize'
import { AllowNull, Column, CreatedAt, Default, HasMany, Is, Model, Table, UpdatedAt } from 'sequelize-typescript'
import { MServer, MServerFormattable } from '@server/types/models/server'
import { AttributesOnly } from '@shared/core-utils'
@@ -51,11 +52,12 @@ export class ServerModel extends Model<Partial<AttributesOnly<ServerModel>>> {
})
BlockedByAccounts: ServerBlocklistModel[]
static load (id: number): Promise<MServer> {
static load (id: number, transaction?: Transaction): Promise<MServer> {
const query = {
where: {
id
}
},
transaction
}
return ServerModel.findOne(query)

View File

@@ -91,9 +91,9 @@ export class VideoCaptionModel extends Model<Partial<AttributesOnly<VideoCaption
Video: VideoModel
@BeforeDestroy
static async removeFiles (instance: VideoCaptionModel) {
static async removeFiles (instance: VideoCaptionModel, options) {
if (!instance.Video) {
instance.Video = await instance.$get('Video')
instance.Video = await instance.$get('Video', { transaction: options.transaction })
}
if (instance.isOwned()) {
@@ -113,8 +113,7 @@ export class VideoCaptionModel extends Model<Partial<AttributesOnly<VideoCaption
const videoInclude = {
model: VideoModel.unscoped(),
attributes: [ 'id', 'remote', 'uuid' ],
where: buildWhereIdOrUUID(videoId),
transaction
where: buildWhereIdOrUUID(videoId)
}
const query = {
@@ -123,7 +122,8 @@ export class VideoCaptionModel extends Model<Partial<AttributesOnly<VideoCaption
},
include: [
videoInclude
]
],
transaction
}
return VideoCaptionModel.findOne(query)

View File

@@ -522,10 +522,10 @@ ON "Account->Actor"."serverId" = "Account->Actor->Server"."id"`
})
}
static loadAndPopulateAccount (id: number): Promise<MChannelBannerAccountDefault> {
static loadAndPopulateAccount (id: number, transaction?: Transaction): Promise<MChannelBannerAccountDefault> {
return VideoChannelModel.unscoped()
.scope([ ScopeNames.WITH_ACTOR_BANNER, ScopeNames.WITH_ACCOUNT ])
.findByPk(id)
.findByPk(id, { transaction })
}
static loadByUrlAndPopulateAccount (url: string): Promise<MChannelBannerAccountDefault> {

View File

@@ -739,6 +739,12 @@ export class VideoCommentModel extends Model<Partial<AttributesOnly<VideoComment
return this.Account.isOwned()
}
markAsDeleted () {
this.text = ''
this.deletedAt = new Date()
this.accountId = null
}
isDeleted () {
return this.deletedAt !== null
}