aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-06-17 10:49:37 +0200
committerChocobozzz <me@florianbigard.com>2022-06-17 11:55:03 +0200
commit3396e6534592865f184ee2db32a75957c42cb887 (patch)
tree324aeab92a27f2ffd1e8a16b09f0b5509bf8f477 /server/models/video
parentb9e49a45f5441fd1a2d49a10b88aaf4d425dc992 (diff)
downloadPeerTube-3396e6534592865f184ee2db32a75957c42cb887.tar.gz
PeerTube-3396e6534592865f184ee2db32a75957c42cb887.tar.zst
PeerTube-3396e6534592865f184ee2db32a75957c42cb887.zip
Optimize broadcast job creation
Diffstat (limited to 'server/models/video')
-rw-r--r--server/models/video/video-share.ts25
1 files changed, 11 insertions, 14 deletions
diff --git a/server/models/video/video-share.ts b/server/models/video/video-share.ts
index ad95dec6e..ca63bb2d9 100644
--- a/server/models/video/video-share.ts
+++ b/server/models/video/video-share.ts
@@ -3,7 +3,7 @@ import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Mode
3import { AttributesOnly } from '@shared/typescript-utils' 3import { AttributesOnly } from '@shared/typescript-utils'
4import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' 4import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
5import { CONSTRAINTS_FIELDS } from '../../initializers/constants' 5import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
6import { MActorDefault } from '../../types/models' 6import { MActorDefault, MActorFollowersUrl, MActorId } from '../../types/models'
7import { MVideoShareActor, MVideoShareFull } from '../../types/models/video' 7import { MVideoShareActor, MVideoShareFull } from '../../types/models/video'
8import { ActorModel } from '../actor/actor' 8import { ActorModel } from '../actor/actor'
9import { buildLocalActorIdsIn, throwIfNotValid } from '../utils' 9import { buildLocalActorIdsIn, throwIfNotValid } from '../utils'
@@ -107,22 +107,19 @@ export class VideoShareModel extends Model<Partial<AttributesOnly<VideoShareMode
107 }) 107 })
108 } 108 }
109 109
110 static loadActorsByShare (videoId: number, t: Transaction): Promise<MActorDefault[]> { 110 static listActorIdsAndFollowerUrlsByShare (videoId: number, t: Transaction) {
111 const query = { 111 const query = `SELECT "actor"."id" AS "id", "actor"."followersUrl" AS "followersUrl" ` +
112 where: { 112 `FROM "videoShare" ` +
113 videoId 113 `INNER JOIN "actor" ON "actor"."id" = "videoShare"."actorId" ` +
114 }, 114 `WHERE "videoShare"."videoId" = :videoId`
115 include: [ 115
116 { 116 const options = {
117 model: ActorModel, 117 type: QueryTypes.SELECT as QueryTypes.SELECT,
118 required: true 118 replacements: { videoId },
119 }
120 ],
121 transaction: t 119 transaction: t
122 } 120 }
123 121
124 return VideoShareModel.scope(ScopeNames.FULL).findAll(query) 122 return VideoShareModel.sequelize.query<MActorId & MActorFollowersUrl>(query, options)
125 .then((res: MVideoShareFull[]) => res.map(r => r.Actor))
126 } 123 }
127 124
128 static loadActorsWhoSharedVideosOf (actorOwnerId: number, t: Transaction): Promise<MActorDefault[]> { 125 static loadActorsWhoSharedVideosOf (actorOwnerId: number, t: Transaction): Promise<MActorDefault[]> {