aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/actor
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/actor')
-rw-r--r--server/models/actor/actor.ts61
1 files changed, 20 insertions, 41 deletions
diff --git a/server/models/actor/actor.ts b/server/models/actor/actor.ts
index 93145b8ae..943b7364f 100644
--- a/server/models/actor/actor.ts
+++ b/server/models/actor/actor.ts
@@ -1,5 +1,5 @@
1import { values } from 'lodash' 1import { values } from 'lodash'
2import { literal, Op, Transaction } from 'sequelize' 2import { literal, Op, QueryTypes, Transaction } from 'sequelize'
3import { 3import {
4 AllowNull, 4 AllowNull,
5 BelongsTo, 5 BelongsTo,
@@ -43,15 +43,18 @@ import {
43 MActorAccountChannelId, 43 MActorAccountChannelId,
44 MActorAPAccount, 44 MActorAPAccount,
45 MActorAPChannel, 45 MActorAPChannel,
46 MActorFollowersUrl,
46 MActorFormattable, 47 MActorFormattable,
47 MActorFull, 48 MActorFull,
48 MActorHost, 49 MActorHost,
50 MActorId,
49 MActorServer, 51 MActorServer,
50 MActorSummaryFormattable, 52 MActorSummaryFormattable,
51 MActorUrl, 53 MActorUrl,
52 MActorWithInboxes 54 MActorWithInboxes
53} from '../../types/models' 55} from '../../types/models'
54import { AccountModel } from '../account/account' 56import { AccountModel } from '../account/account'
57import { getServerActor } from '../application/application'
55import { ServerModel } from '../server/server' 58import { ServerModel } from '../server/server'
56import { isOutdated, throwIfNotValid } from '../utils' 59import { isOutdated, throwIfNotValid } from '../utils'
57import { VideoModel } from '../video/video' 60import { VideoModel } from '../video/video'
@@ -304,7 +307,10 @@ export class ActorModel extends Model<Partial<AttributesOnly<ActorModel>>> {
304 }) 307 })
305 VideoChannel: VideoChannelModel 308 VideoChannel: VideoChannelModel
306 309
307 static load (id: number): Promise<MActor> { 310 static async load (id: number): Promise<MActor> {
311 const actorServer = await getServerActor()
312 if (id === actorServer.id) return actorServer
313
308 return ActorModel.unscoped().findByPk(id) 314 return ActorModel.unscoped().findByPk(id)
309 } 315 }
310 316
@@ -312,48 +318,21 @@ export class ActorModel extends Model<Partial<AttributesOnly<ActorModel>>> {
312 return ActorModel.scope(ScopeNames.FULL).findByPk(id) 318 return ActorModel.scope(ScopeNames.FULL).findByPk(id)
313 } 319 }
314 320
315 static loadFromAccountByVideoId (videoId: number, transaction: Transaction): Promise<MActor> { 321 static loadAccountActorFollowerUrlByVideoId (videoId: number, transaction: Transaction) {
316 const query = { 322 const query = `SELECT "actor"."id" AS "id", "actor"."followersUrl" AS "followersUrl" ` +
317 include: [ 323 `FROM "actor" ` +
318 { 324 `INNER JOIN "account" ON "actor"."id" = "account"."actorId" ` +
319 attributes: [ 'id' ], 325 `INNER JOIN "videoChannel" ON "videoChannel"."accountId" = "account"."id" ` +
320 model: AccountModel.unscoped(), 326 `INNER JOIN "video" ON "video"."channelId" = "videoChannel"."id" AND "video"."id" = :videoId`
321 required: true, 327
322 include: [ 328 const options = {
323 { 329 type: QueryTypes.SELECT as QueryTypes.SELECT,
324 attributes: [ 'id' ], 330 replacements: { videoId },
325 model: VideoChannelModel.unscoped(), 331 plain: true as true,
326 required: true,
327 include: [
328 {
329 attributes: [ 'id' ],
330 model: VideoModel.unscoped(),
331 required: true,
332 where: {
333 id: videoId
334 }
335 }
336 ]
337 }
338 ]
339 }
340 ],
341 transaction 332 transaction
342 } 333 }
343 334
344 return ActorModel.unscoped().findOne(query) 335 return ActorModel.sequelize.query<MActorId & MActorFollowersUrl>(query, options)
345 }
346
347 static isActorUrlExist (url: string) {
348 const query = {
349 raw: true,
350 where: {
351 url
352 }
353 }
354
355 return ActorModel.unscoped().findOne(query)
356 .then(a => !!a)
357 } 336 }
358 337
359 static listByFollowersUrls (followersUrls: string[], transaction?: Transaction): Promise<MActorFull[]> { 338 static listByFollowersUrls (followersUrls: string[], transaction?: Transaction): Promise<MActorFull[]> {