]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/video/video-share.ts
Add simulate many viewers script
[github/Chocobozzz/PeerTube.git] / server / models / video / video-share.ts
index 5059c1fa69cb55893117b7f1b89075d0771b1d7b..ad95dec6e72787340deace90ac26adf2f82012cd 100644 (file)
@@ -1,10 +1,11 @@
 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/typescript-utils'
 import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
 import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
 import { MActorDefault } from '../../types/models'
 import { MVideoShareActor, MVideoShareFull } from '../../types/models/video'
-import { ActorModel } from '../activitypub/actor'
+import { ActorModel } from '../actor/actor'
 import { buildLocalActorIdsIn, throwIfNotValid } from '../utils'
 import { VideoModel } from './video'
 
@@ -50,7 +51,7 @@ enum ScopeNames {
     }
   ]
 })
-export class VideoShareModel extends Model {
+export class VideoShareModel extends Model<Partial<AttributesOnly<VideoShareModel>>> {
 
   @AllowNull(false)
   @Is('VideoShareUrl', value => throwIfNotValid(value, isActivityPubUrlValid, 'url'))
@@ -182,7 +183,10 @@ export class VideoShareModel extends Model {
       transaction: t
     }
 
-    return VideoShareModel.findAndCountAll(query)
+    return Promise.all([
+      VideoShareModel.count(query),
+      VideoShareModel.findAll(query)
+    ]).then(([ total, data ]) => ({ total, data }))
   }
 
   static listRemoteShareUrlsOfLocalVideos () {