]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/activitypub/actor-follow.ts
Speed up overviews route
[github/Chocobozzz/PeerTube.git] / server / models / activitypub / actor-follow.ts
index 81fcf700187fd86160116d0dc30548849b10a027..27bb43daedf6d729418a70d75d11339a00bc5afa 100644 (file)
@@ -19,7 +19,7 @@ import {
   UpdatedAt
 } from 'sequelize-typescript'
 import { FollowState } from '../../../shared/models/actors'
-import { AccountFollow } from '../../../shared/models/actors/follow.model'
+import { ActorFollow } from '../../../shared/models/actors/follow.model'
 import { logger } from '../../helpers/logger'
 import { getServerActor } from '../../helpers/utils'
 import { ACTOR_FOLLOW_SCORE } from '../../initializers'
@@ -169,9 +169,6 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
 
   static loadByActorAndTargetNameAndHostForAPI (actorId: number, targetName: string, targetHost: string, t?: Sequelize.Transaction) {
     const actorFollowingPartInclude: IIncludeOptions = {
-      attributes: {
-        exclude: unusedActorAttributesForAPI
-      },
       model: ActorModel,
       required: true,
       as: 'ActorFollowing',
@@ -203,7 +200,12 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
         actorId
       },
       include: [
-        actorFollowingPartInclude
+        actorFollowingPartInclude,
+        {
+          model: ActorModel,
+          required: true,
+          as: 'ActorFollower'
+        }
       ],
       transaction: t
     }
@@ -323,15 +325,13 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
       },
       include: [
         {
-          attributes: {
-            exclude: unusedActorAttributesForAPI
-          },
-          model: ActorModel,
+          attributes: [ 'id' ],
+          model: ActorModel.unscoped(),
           as: 'ActorFollowing',
           required: true,
           include: [
             {
-              model: VideoChannelModel,
+              model: VideoChannelModel.unscoped(),
               required: true,
               include: [
                 {
@@ -342,7 +342,7 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
                   required: true
                 },
                 {
-                  model: AccountModel,
+                  model: AccountModel.unscoped(),
                   required: true,
                   include: [
                     {
@@ -529,7 +529,7 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
     return ActorFollowModel.findAll(query)
   }
 
-  toFormattedJSON (): AccountFollow {
+  toFormattedJSON (): ActorFollow {
     const follower = this.ActorFollower.toFormattedJSON()
     const following = this.ActorFollowing.toFormattedJSON()