diff options
author | Chocobozzz <me@florianbigard.com> | 2021-05-27 16:12:41 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-05-27 16:12:41 +0200 |
commit | 8f608a4cb22ab232cfab20665050764b38bac9c7 (patch) | |
tree | 6a6785aae79bf5939ad7b7a50a1bd8031268d2b4 /server/models/redundancy | |
parent | 030ccfce59a8cb8f2fee6ea8dd363ba635c5c5c2 (diff) | |
parent | c215e627b575d2c4085ccb222f4ca8d0237b7552 (diff) | |
download | PeerTube-8f608a4cb22ab232cfab20665050764b38bac9c7.tar.gz PeerTube-8f608a4cb22ab232cfab20665050764b38bac9c7.tar.zst PeerTube-8f608a4cb22ab232cfab20665050764b38bac9c7.zip |
Merge branch 'develop' into shorter-URLs-channels-accounts
Diffstat (limited to 'server/models/redundancy')
-rw-r--r-- | server/models/redundancy/video-redundancy.ts | 51 |
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 @@ | |||
1 | import { sample } from 'lodash' | 1 | import { sample } from 'lodash' |
2 | import { FindOptions, literal, Op, QueryTypes, Transaction, WhereOptions } from 'sequelize' | 2 | import { literal, Op, QueryTypes, Transaction, WhereOptions } from 'sequelize' |
3 | import { | 3 | import { |
4 | AllowNull, | 4 | AllowNull, |
5 | BeforeDestroy, | 5 | BeforeDestroy, |
@@ -16,6 +16,7 @@ import { | |||
16 | } from 'sequelize-typescript' | 16 | } from 'sequelize-typescript' |
17 | import { getServerActor } from '@server/models/application/application' | 17 | import { getServerActor } from '@server/models/application/application' |
18 | import { MActor, MVideoForRedundancyAPI, MVideoRedundancy, MVideoRedundancyAP, MVideoRedundancyVideo } from '@server/types/models' | 18 | import { MActor, MVideoForRedundancyAPI, MVideoRedundancy, MVideoRedundancyAP, MVideoRedundancyVideo } from '@server/types/models' |
19 | import { AttributesOnly } from '@shared/core-utils' | ||
19 | import { VideoRedundanciesTarget } from '@shared/models/redundancy/video-redundancies-filters.model' | 20 | import { VideoRedundanciesTarget } from '@shared/models/redundancy/video-redundancies-filters.model' |
20 | import { | 21 | import { |
21 | FileRedundancyInformation, | 22 | FileRedundancyInformation, |
@@ -29,7 +30,7 @@ import { isActivityPubUrlValid, isUrlValid } from '../../helpers/custom-validato | |||
29 | import { logger } from '../../helpers/logger' | 30 | import { logger } from '../../helpers/logger' |
30 | import { CONFIG } from '../../initializers/config' | 31 | import { CONFIG } from '../../initializers/config' |
31 | import { CONSTRAINTS_FIELDS, MIMETYPES } from '../../initializers/constants' | 32 | import { CONSTRAINTS_FIELDS, MIMETYPES } from '../../initializers/constants' |
32 | import { ActorModel } from '../activitypub/actor' | 33 | import { ActorModel } from '../actor/actor' |
33 | import { ServerModel } from '../server/server' | 34 | import { ServerModel } from '../server/server' |
34 | import { getSort, getVideoSort, parseAggregateResult, throwIfNotValid } from '../utils' | 35 | import { getSort, getVideoSort, parseAggregateResult, throwIfNotValid } from '../utils' |
35 | import { ScheduleVideoUpdateModel } from '../video/schedule-video-update' | 36 | import { ScheduleVideoUpdateModel } from '../video/schedule-video-update' |
@@ -84,7 +85,7 @@ export enum ScopeNames { | |||
84 | } | 85 | } |
85 | ] | 86 | ] |
86 | }) | 87 | }) |
87 | export class VideoRedundancyModel extends Model { | 88 | export 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 | ||