mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-04 02:09:37 +02:00
Optimize activity actor load in AP processors
This commit is contained in:
parent
d4defe07d2
commit
e587e0ecee
16 changed files with 110 additions and 89 deletions
|
@ -7,34 +7,32 @@ import { ActorModel } from '../../../models/activitypub/actor'
|
|||
import { VideoModel } from '../../../models/video/video'
|
||||
import { VideoChannelModel } from '../../../models/video/video-channel'
|
||||
import { VideoCommentModel } from '../../../models/video/video-comment'
|
||||
import { getOrCreateActorAndServerAndModel } from '../actor'
|
||||
import { forwardActivity } from '../send/utils'
|
||||
|
||||
async function processDeleteActivity (activity: ActivityDelete) {
|
||||
async function processDeleteActivity (activity: ActivityDelete, byActor: ActorModel) {
|
||||
const objectUrl = typeof activity.object === 'string' ? activity.object : activity.object.id
|
||||
|
||||
if (activity.actor === objectUrl) {
|
||||
let actor = await ActorModel.loadByUrl(activity.actor)
|
||||
if (!actor) return undefined
|
||||
// We need more attributes (all the account and channel)
|
||||
const byActorFull = await ActorModel.loadByUrlAndPopulateAccountAndChannel(byActor.url)
|
||||
|
||||
if (actor.type === 'Person') {
|
||||
if (!actor.Account) throw new Error('Actor ' + actor.url + ' is a person but we cannot find it in database.')
|
||||
if (byActorFull.type === 'Person') {
|
||||
if (!byActorFull.Account) throw new Error('Actor ' + byActorFull.url + ' is a person but we cannot find it in database.')
|
||||
|
||||
actor.Account.Actor = await actor.Account.$get('Actor') as ActorModel
|
||||
return retryTransactionWrapper(processDeleteAccount, actor.Account)
|
||||
} else if (actor.type === 'Group') {
|
||||
if (!actor.VideoChannel) throw new Error('Actor ' + actor.url + ' is a group but we cannot find it in database.')
|
||||
byActorFull.Account.Actor = await byActorFull.Account.$get('Actor') as ActorModel
|
||||
return retryTransactionWrapper(processDeleteAccount, byActorFull.Account)
|
||||
} else if (byActorFull.type === 'Group') {
|
||||
if (!byActorFull.VideoChannel) throw new Error('Actor ' + byActorFull.url + ' is a group but we cannot find it in database.')
|
||||
|
||||
actor.VideoChannel.Actor = await actor.VideoChannel.$get('Actor') as ActorModel
|
||||
return retryTransactionWrapper(processDeleteVideoChannel, actor.VideoChannel)
|
||||
byActorFull.VideoChannel.Actor = await byActorFull.VideoChannel.$get('Actor') as ActorModel
|
||||
return retryTransactionWrapper(processDeleteVideoChannel, byActorFull.VideoChannel)
|
||||
}
|
||||
}
|
||||
|
||||
const actor = await getOrCreateActorAndServerAndModel(activity.actor)
|
||||
{
|
||||
const videoCommentInstance = await VideoCommentModel.loadByUrlAndPopulateAccount(objectUrl)
|
||||
if (videoCommentInstance) {
|
||||
return retryTransactionWrapper(processDeleteVideoComment, actor, videoCommentInstance, activity)
|
||||
return retryTransactionWrapper(processDeleteVideoComment, byActor, videoCommentInstance, activity)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,7 +41,7 @@ async function processDeleteActivity (activity: ActivityDelete) {
|
|||
if (videoInstance) {
|
||||
if (videoInstance.isOwned()) throw new Error(`Remote instance cannot delete owned video ${videoInstance.url}.`)
|
||||
|
||||
return retryTransactionWrapper(processDeleteVideo, actor, videoInstance)
|
||||
return retryTransactionWrapper(processDeleteVideo, byActor, videoInstance)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue