1
0
Fork 0

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

@ -352,13 +352,18 @@ describe('Object storage for video static file privacy', function () {
await makeRawRequest({ url, token: server.accessToken, expectedStatus: HttpStatusCode.OK_200 }) await makeRawRequest({ url, token: server.accessToken, expectedStatus: HttpStatusCode.OK_200 })
await makeRawRequest({ url, query: { videoFileToken: fileToken }, expectedStatus: HttpStatusCode.OK_200 }) await makeRawRequest({ url, query: { videoFileToken: fileToken }, expectedStatus: HttpStatusCode.OK_200 })
if (videoPassword) {
await makeRawRequest({ url, headers: { 'x-peertube-video-password': videoPassword }, expectedStatus: HttpStatusCode.OK_200 })
}
await makeRawRequest({ url, token: userToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) await makeRawRequest({ url, token: userToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
await makeRawRequest({ url, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) await makeRawRequest({ url, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
await makeRawRequest({ url, query: { videoFileToken: unrelatedFileToken }, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) await makeRawRequest({ url, query: { videoFileToken: unrelatedFileToken }, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
if (videoPassword) { if (videoPassword) {
await makeRawRequest({
url,
headers: { 'x-peertube-video-password': videoPassword },
expectedStatus: HttpStatusCode.OK_200
})
await makeRawRequest({ await makeRawRequest({
url, url,
headers: { 'x-peertube-video-password': 'incorrectPassword' }, headers: { 'x-peertube-video-password': 'incorrectPassword' },

View file

@ -64,7 +64,7 @@ function inboxController (req: express.Request, res: express.Response) {
} }
// Only keep activities we are able to process // Only keep activities we are able to process
logger.debug('Filtering %d activities...', activities.length) logger.debug('Filtering %d activities...', activities.length, { activities })
activities = activities.filter(a => isActivityValid(a)) activities = activities.filter(a => isActivityValid(a))
logger.debug('We keep %d activities.', activities.length, { activities }) logger.debug('We keep %d activities.', activities.length, { activities })

View file

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

View file

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

View file

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

View file

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

View file

@ -71,12 +71,26 @@ export enum ScopeNames {
required: true, required: true,
include: [ include: [
{ {
model: VideoChannelModel, model: VideoChannelModel.unscoped(),
attributes: [ 'id', 'accountId' ],
required: true, required: true,
include: [ include: [
{ {
model: AccountModel, attributes: [ 'id', 'url' ],
model: ActorModel.unscoped(),
required: true required: true
},
{
attributes: [ 'id' ],
model: AccountModel.unscoped(),
required: true,
include: [
{
attributes: [ 'id', 'url' ],
model: ActorModel.unscoped(),
required: true
}
]
} }
] ]
} }

View file

@ -5,6 +5,7 @@ import {
MAccountAPI, MAccountAPI,
MAccountDefault, MAccountDefault,
MAccountFormattable, MAccountFormattable,
MAccountId,
MAccountLight, MAccountLight,
MAccountSummaryBlocks, MAccountSummaryBlocks,
MAccountSummaryFormattable, MAccountSummaryFormattable,
@ -22,6 +23,7 @@ import {
MActorFormattable, MActorFormattable,
MActorHost, MActorHost,
MActorHostOnly, MActorHostOnly,
MActorId,
MActorLight, MActorLight,
MActorSummary, MActorSummary,
MActorSummaryFormattable, MActorSummaryFormattable,
@ -49,6 +51,11 @@ export type MChannelUserId =
Pick<MChannel, 'accountId'> & Pick<MChannel, 'accountId'> &
Use<'Account', MAccountUserId> Use<'Account', MAccountUserId>
export type MChannelAccountIdUrl =
Pick<MChannel, 'id' | 'accountId'> &
Use<'Actor', MActorUrl & MActorId> &
Use<'Account', MAccountId & MAccountUrl>
export type MChannelActor = export type MChannelActor =
MChannel & MChannel &
Use<'Actor', MActor> Use<'Actor', MActor>

View file

@ -1,7 +1,7 @@
import { PickWith, PickWithOpt } from '@peertube/peertube-typescript-utils' import { PickWith, PickWithOpt } from '@peertube/peertube-typescript-utils'
import { VideoCommentModel } from '../../../models/video/video-comment.js' import { VideoCommentModel } from '../../../models/video/video-comment.js'
import { MAccountDefault, MAccountFormattable, MAccountUrl } from '../account/index.js' import { MAccountDefault, MAccountFormattable, MAccountUrl } from '../account/index.js'
import { MVideo, MVideoAccountLight, MVideoFeed, MVideoIdUrl, MVideoUrl } from './video.js' import { MVideo, MVideoAccountIdUrl, MVideoAccountLight, MVideoFeed, MVideoIdUrl, MVideoUrl } from './video.js'
type Use<K extends keyof VideoCommentModel, M> = PickWith<VideoCommentModel, K, M> type Use<K extends keyof VideoCommentModel, M> = PickWith<VideoCommentModel, K, M>
@ -29,12 +29,12 @@ export type MCommentReply =
export type MCommentOwnerVideo = export type MCommentOwnerVideo =
MComment & MComment &
Use<'Account', MAccountDefault> & Use<'Account', MAccountDefault> &
Use<'Video', MVideoAccountLight> Use<'Video', MVideoAccountIdUrl>
export type MCommentOwnerVideoReply = export type MCommentOwnerVideoReply =
MComment & MComment &
Use<'Account', MAccountDefault> & Use<'Account', MAccountDefault> &
Use<'Video', MVideoAccountLight> & Use<'Video', MVideoAccountIdUrl> &
Use<'InReplyToVideoComment', MComment> Use<'InReplyToVideoComment', MComment>
export type MCommentOwnerReplyVideoLight = export type MCommentOwnerReplyVideoLight =

View file

@ -10,6 +10,7 @@ import { MVideoBlacklist, MVideoBlacklistLight, MVideoBlacklistUnfederated } fro
import { MVideoCaptionLanguage, MVideoCaptionLanguageUrl } from './video-caption.js' import { MVideoCaptionLanguage, MVideoCaptionLanguageUrl } from './video-caption.js'
import { import {
MChannelAccountDefault, MChannelAccountDefault,
MChannelAccountIdUrl,
MChannelAccountLight, MChannelAccountLight,
MChannelAccountSummaryFormattable, MChannelAccountSummaryFormattable,
MChannelActor, MChannelActor,
@ -136,6 +137,10 @@ export type MVideoAccountDefault =
MVideo & MVideo &
Use<'VideoChannel', MChannelAccountDefault> Use<'VideoChannel', MChannelAccountDefault>
export type MVideoAccountIdUrl =
MVideo &
Use<'VideoChannel', MChannelAccountIdUrl>
export type MVideoThumbnailAccountDefault = export type MVideoThumbnailAccountDefault =
MVideo & MVideo &
Use<'Thumbnails', MThumbnail[]> & Use<'Thumbnails', MThumbnail[]> &