diff options
author | Chocobozzz <me@florianbigard.com> | 2021-06-15 09:17:19 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-06-15 10:40:06 +0200 |
commit | eae0365b5c5468e51e9795b0e894815ebda86b4a (patch) | |
tree | 5da54b28c94d43d1715a0c69e35eb1cf3a1a959d /server/lib/activitypub | |
parent | 51f636ad0f928bb94069c9143e38df0518f6e4a7 (diff) | |
download | PeerTube-eae0365b5c5468e51e9795b0e894815ebda86b4a.tar.gz PeerTube-eae0365b5c5468e51e9795b0e894815ebda86b4a.tar.zst PeerTube-eae0365b5c5468e51e9795b0e894815ebda86b4a.zip |
Fix missing transactions
Diffstat (limited to 'server/lib/activitypub')
-rw-r--r-- | server/lib/activitypub/follow.ts | 13 | ||||
-rw-r--r-- | server/lib/activitypub/process/process-delete.ts | 7 | ||||
-rw-r--r-- | server/lib/activitypub/process/process-follow.ts | 7 | ||||
-rw-r--r-- | server/lib/activitypub/process/process-undo.ts | 4 |
4 files changed, 15 insertions, 16 deletions
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 @@ | |||
1 | import { MActorFollowActors } from '../../types/models' | 1 | import { Transaction } from 'sequelize' |
2 | import { getServerActor } from '@server/models/application/application' | ||
3 | import { logger } from '../../helpers/logger' | ||
2 | import { CONFIG } from '../../initializers/config' | 4 | import { CONFIG } from '../../initializers/config' |
3 | import { SERVER_ACTOR_NAME } from '../../initializers/constants' | 5 | import { SERVER_ACTOR_NAME } from '../../initializers/constants' |
4 | import { JobQueue } from '../job-queue' | ||
5 | import { logger } from '../../helpers/logger' | ||
6 | import { ServerModel } from '../../models/server/server' | 6 | import { ServerModel } from '../../models/server/server' |
7 | import { getServerActor } from '@server/models/application/application' | 7 | import { MActorFollowActors } from '../../types/models' |
8 | import { JobQueue } from '../job-queue' | ||
8 | 9 | ||
9 | async function autoFollowBackIfNeeded (actorFollow: MActorFollowActors) { | 10 | async function autoFollowBackIfNeeded (actorFollow: MActorFollowActors, transaction?: Transaction) { |
10 | if (!CONFIG.FOLLOWINGS.INSTANCE.AUTO_FOLLOW_BACK.ENABLED) return | 11 | if (!CONFIG.FOLLOWINGS.INSTANCE.AUTO_FOLLOW_BACK.ENABLED) return |
11 | 12 | ||
12 | const follower = actorFollow.ActorFollower | 13 | const follower = actorFollow.ActorFollower |
@@ -16,7 +17,7 @@ async function autoFollowBackIfNeeded (actorFollow: MActorFollowActors) { | |||
16 | 17 | ||
17 | const me = await getServerActor() | 18 | const me = await getServerActor() |
18 | 19 | ||
19 | const server = await ServerModel.load(follower.serverId) | 20 | const server = await ServerModel.load(follower.serverId, transaction) |
20 | const host = server.host | 21 | const host = server.host |
21 | 22 | ||
22 | const payload = { | 23 | 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 { | |||
16 | MChannelActor, | 16 | MChannelActor, |
17 | MCommentOwnerVideo | 17 | MCommentOwnerVideo |
18 | } from '../../../types/models' | 18 | } from '../../../types/models' |
19 | import { markCommentAsDeleted } from '../../video-comment' | ||
20 | import { forwardVideoRelatedActivity } from '../send/utils' | 19 | import { forwardVideoRelatedActivity } from '../send/utils' |
21 | 20 | ||
22 | async function processDeleteActivity (options: APProcessorOptions<ActivityDelete>) { | 21 | async function processDeleteActivity (options: APProcessorOptions<ActivityDelete>) { |
@@ -139,11 +138,9 @@ function processDeleteVideoComment (byActor: MActorSignature, videoComment: MCom | |||
139 | throw new Error(`Account ${byActor.url} does not own video comment ${videoComment.url} or video ${videoComment.Video.url}`) | 138 | throw new Error(`Account ${byActor.url} does not own video comment ${videoComment.url} or video ${videoComment.Video.url}`) |
140 | } | 139 | } |
141 | 140 | ||
142 | await sequelizeTypescript.transaction(async t => { | 141 | videoComment.markAsDeleted() |
143 | markCommentAsDeleted(videoComment) | ||
144 | 142 | ||
145 | await videoComment.save() | 143 | await videoComment.save({ transaction: t }) |
146 | }) | ||
147 | 144 | ||
148 | if (videoComment.Video.isOwned()) { | 145 | if (videoComment.Video.isOwned()) { |
149 | // Don't resend the activity to the sender | 146 | // 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 | |||
43 | if (isFollowingInstance && CONFIG.FOLLOWERS.INSTANCE.ENABLED === false) { | 43 | if (isFollowingInstance && CONFIG.FOLLOWERS.INSTANCE.ENABLED === false) { |
44 | logger.info('Rejecting %s because instance followers are disabled.', targetActor.url) | 44 | logger.info('Rejecting %s because instance followers are disabled.', targetActor.url) |
45 | 45 | ||
46 | await sendReject(activityId, byActor, targetActor) | 46 | sendReject(activityId, byActor, targetActor) |
47 | 47 | ||
48 | return { actorFollow: undefined as MActorFollowActors } | 48 | return { actorFollow: undefined as MActorFollowActors } |
49 | } | 49 | } |
@@ -84,8 +84,9 @@ async function processFollow (byActor: MActorSignature, activityId: string, targ | |||
84 | 84 | ||
85 | // Target sends to actor he accepted the follow request | 85 | // Target sends to actor he accepted the follow request |
86 | if (actorFollow.state === 'accepted') { | 86 | if (actorFollow.state === 'accepted') { |
87 | await sendAccept(actorFollow) | 87 | sendAccept(actorFollow) |
88 | await autoFollowBackIfNeeded(actorFollow) | 88 | |
89 | await autoFollowBackIfNeeded(actorFollow, t) | ||
89 | } | 90 | } |
90 | 91 | ||
91 | return { actorFollow, created, isFollowingInstance, targetActor } | 92 | 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 | |||
106 | const { video } = await getOrCreateAPVideo({ videoObject: cacheFileObject.object }) | 106 | const { video } = await getOrCreateAPVideo({ videoObject: cacheFileObject.object }) |
107 | 107 | ||
108 | return sequelizeTypescript.transaction(async t => { | 108 | return sequelizeTypescript.transaction(async t => { |
109 | const cacheFile = await VideoRedundancyModel.loadByUrl(cacheFileObject.id) | 109 | const cacheFile = await VideoRedundancyModel.loadByUrl(cacheFileObject.id, t) |
110 | if (!cacheFile) { | 110 | if (!cacheFile) { |
111 | logger.debug('Cannot undo unknown video cache %s.', cacheFileObject.id) | 111 | logger.debug('Cannot undo unknown video cache %s.', cacheFileObject.id) |
112 | return | 112 | return |
@@ -114,7 +114,7 @@ async function processUndoCacheFile (byActor: MActorSignature, activity: Activit | |||
114 | 114 | ||
115 | if (cacheFile.actorId !== byActor.id) throw new Error('Cannot delete redundancy ' + cacheFile.url + ' of another actor.') | 115 | if (cacheFile.actorId !== byActor.id) throw new Error('Cannot delete redundancy ' + cacheFile.url + ' of another actor.') |
116 | 116 | ||
117 | await cacheFile.destroy() | 117 | await cacheFile.destroy({ transaction: t }) |
118 | 118 | ||
119 | if (video.isOwned()) { | 119 | if (video.isOwned()) { |
120 | // Don't resend the activity to the sender | 120 | // Don't resend the activity to the sender |