]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/video/video-share.ts
Merge branch 'release/4.2.0' into develop
[github/Chocobozzz/PeerTube.git] / server / models / video / video-share.ts
index ad95dec6e72787340deace90ac26adf2f82012cd..ca63bb2d93c947f07d9f9ca581a40377ead22427 100644 (file)
@@ -3,7 +3,7 @@ import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Mode
 import { AttributesOnly } from '@shared/typescript-utils'
 import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
 import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
-import { MActorDefault } from '../../types/models'
+import { MActorDefault, MActorFollowersUrl, MActorId } from '../../types/models'
 import { MVideoShareActor, MVideoShareFull } from '../../types/models/video'
 import { ActorModel } from '../actor/actor'
 import { buildLocalActorIdsIn, throwIfNotValid } from '../utils'
@@ -107,22 +107,19 @@ export class VideoShareModel extends Model<Partial<AttributesOnly<VideoShareMode
     })
   }
 
-  static loadActorsByShare (videoId: number, t: Transaction): Promise<MActorDefault[]> {
-    const query = {
-      where: {
-        videoId
-      },
-      include: [
-        {
-          model: ActorModel,
-          required: true
-        }
-      ],
+  static listActorIdsAndFollowerUrlsByShare (videoId: number, t: Transaction) {
+    const query = `SELECT "actor"."id" AS "id", "actor"."followersUrl" AS "followersUrl" ` +
+                  `FROM "videoShare" ` +
+                  `INNER JOIN "actor" ON "actor"."id" = "videoShare"."actorId" ` +
+                  `WHERE "videoShare"."videoId" = :videoId`
+
+    const options = {
+      type: QueryTypes.SELECT as QueryTypes.SELECT,
+      replacements: { videoId },
       transaction: t
     }
 
-    return VideoShareModel.scope(ScopeNames.FULL).findAll(query)
-                          .then((res: MVideoShareFull[]) => res.map(r => r.Actor))
+    return VideoShareModel.sequelize.query<MActorId & MActorFollowersUrl>(query, options)
   }
 
   static loadActorsWhoSharedVideosOf (actorOwnerId: number, t: Transaction): Promise<MActorDefault[]> {