diff options
author | Chocobozzz <me@florianbigard.com> | 2022-06-17 10:49:37 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-06-17 11:55:03 +0200 |
commit | 3396e6534592865f184ee2db32a75957c42cb887 (patch) | |
tree | 324aeab92a27f2ffd1e8a16b09f0b5509bf8f477 /server/models/video/video-share.ts | |
parent | b9e49a45f5441fd1a2d49a10b88aaf4d425dc992 (diff) | |
download | PeerTube-3396e6534592865f184ee2db32a75957c42cb887.tar.gz PeerTube-3396e6534592865f184ee2db32a75957c42cb887.tar.zst PeerTube-3396e6534592865f184ee2db32a75957c42cb887.zip |
Optimize broadcast job creation
Diffstat (limited to 'server/models/video/video-share.ts')
-rw-r--r-- | server/models/video/video-share.ts | 25 |
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 | |||
3 | import { AttributesOnly } from '@shared/typescript-utils' | 3 | import { AttributesOnly } from '@shared/typescript-utils' |
4 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' | 4 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' |
5 | import { CONSTRAINTS_FIELDS } from '../../initializers/constants' | 5 | import { CONSTRAINTS_FIELDS } from '../../initializers/constants' |
6 | import { MActorDefault } from '../../types/models' | 6 | import { MActorDefault, MActorFollowersUrl, MActorId } from '../../types/models' |
7 | import { MVideoShareActor, MVideoShareFull } from '../../types/models/video' | 7 | import { MVideoShareActor, MVideoShareFull } from '../../types/models/video' |
8 | import { ActorModel } from '../actor/actor' | 8 | import { ActorModel } from '../actor/actor' |
9 | import { buildLocalActorIdsIn, throwIfNotValid } from '../utils' | 9 | import { 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[]> { |