aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/redundancy/video-redundancy.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/redundancy/video-redundancy.ts')
-rw-r--r--server/models/redundancy/video-redundancy.ts51
1 files changed, 4 insertions, 47 deletions
diff --git a/server/models/redundancy/video-redundancy.ts b/server/models/redundancy/video-redundancy.ts
index 53ebadeaf..ca56a57dc 100644
--- a/server/models/redundancy/video-redundancy.ts
+++ b/server/models/redundancy/video-redundancy.ts
@@ -1,5 +1,5 @@
1import { sample } from 'lodash' 1import { sample } from 'lodash'
2import { FindOptions, literal, Op, QueryTypes, Transaction, WhereOptions } from 'sequelize' 2import { literal, Op, QueryTypes, Transaction, WhereOptions } from 'sequelize'
3import { 3import {
4 AllowNull, 4 AllowNull,
5 BeforeDestroy, 5 BeforeDestroy,
@@ -16,6 +16,7 @@ import {
16} from 'sequelize-typescript' 16} from 'sequelize-typescript'
17import { getServerActor } from '@server/models/application/application' 17import { getServerActor } from '@server/models/application/application'
18import { MActor, MVideoForRedundancyAPI, MVideoRedundancy, MVideoRedundancyAP, MVideoRedundancyVideo } from '@server/types/models' 18import { MActor, MVideoForRedundancyAPI, MVideoRedundancy, MVideoRedundancyAP, MVideoRedundancyVideo } from '@server/types/models'
19import { AttributesOnly } from '@shared/core-utils'
19import { VideoRedundanciesTarget } from '@shared/models/redundancy/video-redundancies-filters.model' 20import { VideoRedundanciesTarget } from '@shared/models/redundancy/video-redundancies-filters.model'
20import { 21import {
21 FileRedundancyInformation, 22 FileRedundancyInformation,
@@ -29,7 +30,7 @@ import { isActivityPubUrlValid, isUrlValid } from '../../helpers/custom-validato
29import { logger } from '../../helpers/logger' 30import { logger } from '../../helpers/logger'
30import { CONFIG } from '../../initializers/config' 31import { CONFIG } from '../../initializers/config'
31import { CONSTRAINTS_FIELDS, MIMETYPES } from '../../initializers/constants' 32import { CONSTRAINTS_FIELDS, MIMETYPES } from '../../initializers/constants'
32import { ActorModel } from '../activitypub/actor' 33import { ActorModel } from '../actor/actor'
33import { ServerModel } from '../server/server' 34import { ServerModel } from '../server/server'
34import { getSort, getVideoSort, parseAggregateResult, throwIfNotValid } from '../utils' 35import { getSort, getVideoSort, parseAggregateResult, throwIfNotValid } from '../utils'
35import { ScheduleVideoUpdateModel } from '../video/schedule-video-update' 36import { ScheduleVideoUpdateModel } from '../video/schedule-video-update'
@@ -84,7 +85,7 @@ export enum ScopeNames {
84 } 85 }
85 ] 86 ]
86}) 87})
87export class VideoRedundancyModel extends Model { 88export class VideoRedundancyModel extends Model<Partial<AttributesOnly<VideoRedundancyModel>>> {
88 89
89 @CreatedAt 90 @CreatedAt
90 createdAt: Date 91 createdAt: Date
@@ -407,50 +408,6 @@ export class VideoRedundancyModel extends Model {
407 return VideoRedundancyModel.scope([ ScopeNames.WITH_VIDEO ]).findOne(query) 408 return VideoRedundancyModel.scope([ ScopeNames.WITH_VIDEO ]).findOne(query)
408 } 409 }
409 410
410 static async getTotalDuplicated (strategy: VideoRedundancyStrategy) {
411 const actor = await getServerActor()
412 const redundancyInclude = {
413 attributes: [],
414 model: VideoRedundancyModel,
415 required: true,
416 where: {
417 actorId: actor.id,
418 strategy
419 }
420 }
421
422 const queryFiles: FindOptions = {
423 include: [ redundancyInclude ]
424 }
425
426 const queryStreamingPlaylists: FindOptions = {
427 include: [
428 {
429 attributes: [],
430 model: VideoModel.unscoped(),
431 required: true,
432 include: [
433 {
434 required: true,
435 attributes: [],
436 model: VideoStreamingPlaylistModel.unscoped(),
437 include: [
438 redundancyInclude
439 ]
440 }
441 ]
442 }
443 ]
444 }
445
446 return Promise.all([
447 VideoFileModel.aggregate('size', 'SUM', queryFiles),
448 VideoFileModel.aggregate('size', 'SUM', queryStreamingPlaylists)
449 ]).then(([ r1, r2 ]) => {
450 return parseAggregateResult(r1) + parseAggregateResult(r2)
451 })
452 }
453
454 static async listLocalExpired () { 411 static async listLocalExpired () {
455 const actor = await getServerActor() 412 const actor = await getServerActor()
456 413