X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fvideo%2Fvideo-share.ts;h=ca63bb2d93c947f07d9f9ca581a40377ead22427;hb=2b621ac0ebe83693bba6354b3482a03ba58143e7;hp=505c305e234826f4ce97da7a2e5d69267aa0e68d;hpb=cf21b2cbef61929177b9c09b5e017c3b7eb8535d;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/video/video-share.ts b/server/models/video/video-share.ts index 505c305e2..ca63bb2d9 100644 --- a/server/models/video/video-share.ts +++ b/server/models/video/video-share.ts @@ -1,9 +1,9 @@ import { literal, Op, QueryTypes, Transaction } from 'sequelize' import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' -import { AttributesOnly } from '@shared/core-utils' +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 { - 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(query, options) } static loadActorsWhoSharedVideosOf (actorOwnerId: number, t: Transaction): Promise { @@ -183,7 +180,10 @@ export class VideoShareModel extends Model ({ total, data })) } static listRemoteShareUrlsOfLocalVideos () {