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

Optimize view endpoint

This commit is contained in:
Chocobozzz 2020-02-04 16:14:33 +01:00
parent 943e519390
commit 2c8776fc31
No known key found for this signature in database
GPG key ID: 583A612D890159BE
6 changed files with 46 additions and 21 deletions

View file

@ -4,19 +4,11 @@ import { ACTIVITY_PUB } from '../../initializers/constants'
import { ActorModel } from '../../models/activitypub/actor'
import { VideoModel } from '../../models/video/video'
import { VideoShareModel } from '../../models/video/video-share'
import {
MActorFollowersUrl,
MActorLight,
MCommentOwner,
MCommentOwnerVideo,
MVideo,
MVideoAccountLight,
MVideoId
} from '../../typings/models'
import { MActorFollowersUrl, MActorLight, MActorUrl, MCommentOwner, MCommentOwnerVideo, MVideoId } from '../../typings/models'
function getRemoteVideoAudience (video: MVideoAccountLight, actorsInvolvedInVideo: MActorFollowersUrl[]): ActivityAudience {
function getRemoteVideoAudience (accountActor: MActorUrl, actorsInvolvedInVideo: MActorFollowersUrl[]): ActivityAudience {
return {
to: [ video.VideoChannel.Account.Actor.url ],
to: [ accountActor.url ],
cc: actorsInvolvedInVideo.map(a => a.followersUrl)
}
}

View file

@ -5,9 +5,9 @@ import { getVideoLikeActivityPubUrl } from '../url'
import { sendVideoRelatedActivity } from './utils'
import { audiencify, getAudience } from '../audience'
import { logger } from '../../../helpers/logger'
import { MActorAudience, MVideoAccountLight, MVideoUrl } from '@server/typings/models'
import { MActorAudience, MVideoImmutable, MVideoUrl } from '@server/typings/models'
async function sendView (byActor: ActorModel, video: MVideoAccountLight, t: Transaction) {
async function sendView (byActor: ActorModel, video: MVideoImmutable, t: Transaction) {
logger.info('Creating job to send view of %s.', video.url)
const activityBuilder = (audience: ActivityAudience) => {

View file

@ -7,12 +7,12 @@ import { JobQueue } from '../../job-queue'
import { getActorsInvolvedInVideo, getAudienceFromFollowersOf, getRemoteVideoAudience } from '../audience'
import { getServerActor } from '../../../helpers/utils'
import { afterCommitIfTransaction } from '../../../helpers/database-utils'
import { MActorWithInboxes, MActor, MActorId, MActorLight, MVideo, MVideoAccountLight, MVideoId } from '../../../typings/models'
import { MActor, MActorId, MActorLight, MActorWithInboxes, MVideoAccountLight, MVideoId, MVideoImmutable } from '../../../typings/models'
import { ContextType } from '@server/helpers/activitypub'
async function sendVideoRelatedActivity (activityBuilder: (audience: ActivityAudience) => Activity, options: {
byActor: MActorLight
video: MVideoAccountLight
video: MVideoImmutable | MVideoAccountLight
transaction?: Transaction
contextType?: ContextType
}) {
@ -22,11 +22,13 @@ async function sendVideoRelatedActivity (activityBuilder: (audience: ActivityAud
// Send to origin
if (video.isOwned() === false) {
const audience = getRemoteVideoAudience(video, actorsInvolvedInVideo)
const accountActor = (video as MVideoAccountLight).VideoChannel?.Account?.Actor || await ActorModel.loadAccountActorByVideoId(video.id)
const audience = getRemoteVideoAudience(accountActor, actorsInvolvedInVideo)
const activity = activityBuilder(audience)
return afterCommitIfTransaction(transaction, () => {
return unicastTo(activity, byActor, video.VideoChannel.Account.Actor.getSharedInbox(), contextType)
return unicastTo(activity, byActor, accountActor.getSharedInbox(), contextType)
})
}