1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-06 03:50:26 +02:00

Reduce video comment sql query size

This commit is contained in:
Chocobozzz 2023-10-31 10:02:19 +01:00
parent 2e556debca
commit 443358ccce
No known key found for this signature in database
GPG key ID: 583A612D890159BE
10 changed files with 55 additions and 15 deletions

View file

@ -32,6 +32,7 @@ import {
sendVideoRelatedActivity,
unicastTo
} from './shared/index.js'
import { AccountModel } from '@server/models/account/account.js'
const lTags = loggerTagsFactory('ap', 'create')
@ -114,6 +115,8 @@ async function sendCreateVideoComment (comment: MCommentOwnerVideo, transaction:
const isOrigin = comment.Video.isOwned()
const byActor = comment.Account.Actor
const videoAccount = await AccountModel.load(comment.Video.VideoChannel.Account.id, transaction)
const threadParentComments = await VideoCommentModel.listThreadParentComments(comment, transaction)
const commentObject = comment.toActivityPubObject(threadParentComments) as VideoCommentObject
@ -170,7 +173,7 @@ async function sendCreateVideoComment (comment: MCommentOwnerVideo, transaction:
return unicastTo({
data: createActivity,
byActor,
toActorUrl: comment.Video.VideoChannel.Account.Actor.getSharedInbox(),
toActorUrl: videoAccount.Actor.getSharedInbox(),
contextType: 'Comment'
})
})

View file

@ -11,6 +11,7 @@ import { audiencify } from '../audience.js'
import { getDeleteActivityPubUrl } from '../url.js'
import { getActorsInvolvedInVideo, getVideoCommentAudience } from './shared/index.js'
import { broadcastToActors, broadcastToFollowers, sendVideoRelatedActivity, unicastTo } from './shared/send-utils.js'
import { AccountModel } from '@server/models/account/account.js'
async function sendDeleteVideo (video: MVideoAccountLight, transaction: Transaction) {
logger.info('Creating job to broadcast delete of video %s.', video.url)
@ -55,9 +56,12 @@ async function sendDeleteVideoComment (videoComment: MCommentOwnerVideo, transac
const isVideoOrigin = videoComment.Video.isOwned()
const url = getDeleteActivityPubUrl(videoComment.url)
const videoAccount = await AccountModel.load(videoComment.Video.VideoChannel.Account.id, transaction)
const byActor = videoComment.isOwned()
? videoComment.Account.Actor
: videoComment.Video.VideoChannel.Account.Actor
: videoAccount.Actor
const threadParentComments = await VideoCommentModel.listThreadParentComments(videoComment, transaction)
const threadParentCommentsFiltered = threadParentComments.filter(c => !c.isDeleted())
@ -105,7 +109,7 @@ async function sendDeleteVideoComment (videoComment: MCommentOwnerVideo, transac
return unicastTo({
data: activity,
byActor,
toActorUrl: videoComment.Video.VideoChannel.Account.Actor.getSharedInbox(),
toActorUrl: videoAccount.Actor.getSharedInbox(),
contextType: 'Delete'
})
})

View file

@ -53,10 +53,10 @@ function getAudienceFromFollowersOf (actorsInvolvedInObject: MActorFollowersUrl[
async function getActorsInvolvedInVideo (video: MVideoId, t: Transaction) {
const actors = await VideoShareModel.listActorIdsAndFollowerUrlsByShare(video.id, t)
const videoAll = video as VideoModel
const alreadyLoadedActor = (video as VideoModel).VideoChannel?.Account?.Actor
const videoActor = videoAll.VideoChannel?.Account
? videoAll.VideoChannel.Account.Actor
const videoActor = alreadyLoadedActor?.url && alreadyLoadedActor?.followersUrl
? alreadyLoadedActor
: await ActorModel.loadAccountActorFollowerUrlByVideoId(video.id, t)
actors.push(videoActor)

View file

@ -173,6 +173,8 @@ async function resolveRemoteParentComment (params: ResolveThreadParams) {
}) as MCommentOwner
comment.Account = actor ? actor.Account : null
logger.debug('Created remote comment %s', comment.url, { comment })
return resolveThread({
url: body.inReplyTo,
comments: comments.concat([ comment ]),