From eae0365b5c5468e51e9795b0e894815ebda86b4a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 15 Jun 2021 09:17:19 +0200 Subject: Fix missing transactions --- server/lib/activitypub/follow.ts | 13 +++++++------ server/lib/activitypub/process/process-delete.ts | 7 ++----- server/lib/activitypub/process/process-follow.ts | 7 ++++--- server/lib/activitypub/process/process-undo.ts | 4 ++-- 4 files changed, 15 insertions(+), 16 deletions(-) (limited to 'server/lib/activitypub') diff --git a/server/lib/activitypub/follow.ts b/server/lib/activitypub/follow.ts index 351499bd1..c1bd667e0 100644 --- a/server/lib/activitypub/follow.ts +++ b/server/lib/activitypub/follow.ts @@ -1,12 +1,13 @@ -import { MActorFollowActors } from '../../types/models' +import { Transaction } from 'sequelize' +import { getServerActor } from '@server/models/application/application' +import { logger } from '../../helpers/logger' import { CONFIG } from '../../initializers/config' import { SERVER_ACTOR_NAME } from '../../initializers/constants' -import { JobQueue } from '../job-queue' -import { logger } from '../../helpers/logger' import { ServerModel } from '../../models/server/server' -import { getServerActor } from '@server/models/application/application' +import { MActorFollowActors } from '../../types/models' +import { JobQueue } from '../job-queue' -async function autoFollowBackIfNeeded (actorFollow: MActorFollowActors) { +async function autoFollowBackIfNeeded (actorFollow: MActorFollowActors, transaction?: Transaction) { if (!CONFIG.FOLLOWINGS.INSTANCE.AUTO_FOLLOW_BACK.ENABLED) return const follower = actorFollow.ActorFollower @@ -16,7 +17,7 @@ async function autoFollowBackIfNeeded (actorFollow: MActorFollowActors) { const me = await getServerActor() - const server = await ServerModel.load(follower.serverId) + const server = await ServerModel.load(follower.serverId, transaction) const host = server.host const payload = { diff --git a/server/lib/activitypub/process/process-delete.ts b/server/lib/activitypub/process/process-delete.ts index 44f6a87b0..1d2279df5 100644 --- a/server/lib/activitypub/process/process-delete.ts +++ b/server/lib/activitypub/process/process-delete.ts @@ -16,7 +16,6 @@ import { MChannelActor, MCommentOwnerVideo } from '../../../types/models' -import { markCommentAsDeleted } from '../../video-comment' import { forwardVideoRelatedActivity } from '../send/utils' async function processDeleteActivity (options: APProcessorOptions) { @@ -139,11 +138,9 @@ function processDeleteVideoComment (byActor: MActorSignature, videoComment: MCom throw new Error(`Account ${byActor.url} does not own video comment ${videoComment.url} or video ${videoComment.Video.url}`) } - await sequelizeTypescript.transaction(async t => { - markCommentAsDeleted(videoComment) + videoComment.markAsDeleted() - await videoComment.save() - }) + await videoComment.save({ transaction: t }) if (videoComment.Video.isOwned()) { // Don't resend the activity to the sender diff --git a/server/lib/activitypub/process/process-follow.ts b/server/lib/activitypub/process/process-follow.ts index 9009c6469..f85238f8e 100644 --- a/server/lib/activitypub/process/process-follow.ts +++ b/server/lib/activitypub/process/process-follow.ts @@ -43,7 +43,7 @@ async function processFollow (byActor: MActorSignature, activityId: string, targ if (isFollowingInstance && CONFIG.FOLLOWERS.INSTANCE.ENABLED === false) { logger.info('Rejecting %s because instance followers are disabled.', targetActor.url) - await sendReject(activityId, byActor, targetActor) + sendReject(activityId, byActor, targetActor) return { actorFollow: undefined as MActorFollowActors } } @@ -84,8 +84,9 @@ async function processFollow (byActor: MActorSignature, activityId: string, targ // Target sends to actor he accepted the follow request if (actorFollow.state === 'accepted') { - await sendAccept(actorFollow) - await autoFollowBackIfNeeded(actorFollow) + sendAccept(actorFollow) + + await autoFollowBackIfNeeded(actorFollow, t) } return { actorFollow, created, isFollowingInstance, targetActor } diff --git a/server/lib/activitypub/process/process-undo.ts b/server/lib/activitypub/process/process-undo.ts index fdb8dac24..d4b2a795f 100644 --- a/server/lib/activitypub/process/process-undo.ts +++ b/server/lib/activitypub/process/process-undo.ts @@ -106,7 +106,7 @@ async function processUndoCacheFile (byActor: MActorSignature, activity: Activit const { video } = await getOrCreateAPVideo({ videoObject: cacheFileObject.object }) return sequelizeTypescript.transaction(async t => { - const cacheFile = await VideoRedundancyModel.loadByUrl(cacheFileObject.id) + const cacheFile = await VideoRedundancyModel.loadByUrl(cacheFileObject.id, t) if (!cacheFile) { logger.debug('Cannot undo unknown video cache %s.', cacheFileObject.id) return @@ -114,7 +114,7 @@ async function processUndoCacheFile (byActor: MActorSignature, activity: Activit if (cacheFile.actorId !== byActor.id) throw new Error('Cannot delete redundancy ' + cacheFile.url + ' of another actor.') - await cacheFile.destroy() + await cacheFile.destroy({ transaction: t }) if (video.isOwned()) { // Don't resend the activity to the sender -- cgit v1.2.3