]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/redundancy/video-redundancy.ts
Add expiresOn index
[github/Chocobozzz/PeerTube.git] / server / models / redundancy / video-redundancy.ts
index b6538c8fd51089f18fa948124b0154292c2e5bcc..ccda023e018388bcfabb7a5f4153946c6cd0ffb6 100644 (file)
@@ -1,5 +1,5 @@
 import { sample } from 'lodash'
-import { FindOptions, literal, Op, QueryTypes, Transaction, WhereOptions } from 'sequelize'
+import { literal, Op, QueryTypes, Transaction, WhereOptions } from 'sequelize'
 import {
   AllowNull,
   BeforeDestroy,
@@ -16,6 +16,7 @@ import {
 } from 'sequelize-typescript'
 import { getServerActor } from '@server/models/application/application'
 import { MActor, MVideoForRedundancyAPI, MVideoRedundancy, MVideoRedundancyAP, MVideoRedundancyVideo } from '@server/types/models'
+import { AttributesOnly } from '@shared/core-utils'
 import { VideoRedundanciesTarget } from '@shared/models/redundancy/video-redundancies-filters.model'
 import {
   FileRedundancyInformation,
@@ -78,13 +79,16 @@ export enum ScopeNames {
     {
       fields: [ 'actorId' ]
     },
+    {
+      fields: [ 'expiresOn' ]
+    },
     {
       fields: [ 'url' ],
       unique: true
     }
   ]
 })
-export class VideoRedundancyModel extends Model {
+export class VideoRedundancyModel extends Model<Partial<AttributesOnly<VideoRedundancyModel>>> {
 
   @CreatedAt
   createdAt: Date
@@ -407,50 +411,6 @@ export class VideoRedundancyModel extends Model {
     return VideoRedundancyModel.scope([ ScopeNames.WITH_VIDEO ]).findOne(query)
   }
 
-  static async getTotalDuplicated (strategy: VideoRedundancyStrategy) {
-    const actor = await getServerActor()
-    const redundancyInclude = {
-      attributes: [],
-      model: VideoRedundancyModel,
-      required: true,
-      where: {
-        actorId: actor.id,
-        strategy
-      }
-    }
-
-    const queryFiles: FindOptions = {
-      include: [ redundancyInclude ]
-    }
-
-    const queryStreamingPlaylists: FindOptions = {
-      include: [
-        {
-          attributes: [],
-          model: VideoModel.unscoped(),
-          required: true,
-          include: [
-            {
-              required: true,
-              attributes: [],
-              model: VideoStreamingPlaylistModel.unscoped(),
-              include: [
-                redundancyInclude
-              ]
-            }
-          ]
-        }
-      ]
-    }
-
-    return Promise.all([
-      VideoFileModel.aggregate('size', 'SUM', queryFiles),
-      VideoFileModel.aggregate('size', 'SUM', queryStreamingPlaylists)
-    ]).then(([ r1, r2 ]) => {
-      return parseAggregateResult(r1) + parseAggregateResult(r2)
-    })
-  }
-
   static async listLocalExpired () {
     const actor = await getServerActor()