import { sample } from 'lodash'
-import { FindOptions, literal, Op, QueryTypes, Transaction, WhereOptions } from 'sequelize'
+import { literal, Op, QueryTypes, Transaction, WhereOptions } from 'sequelize'
import {
AllowNull,
BeforeDestroy,
} 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,
import { logger } from '../../helpers/logger'
import { CONFIG } from '../../initializers/config'
import { CONSTRAINTS_FIELDS, MIMETYPES } from '../../initializers/constants'
-import { ActorModel } from '../activitypub/actor'
+import { ActorModel } from '../actor/actor'
import { ServerModel } from '../server/server'
import { getSort, getVideoSort, parseAggregateResult, throwIfNotValid } from '../utils'
+import { ScheduleVideoUpdateModel } from '../video/schedule-video-update'
import { VideoModel } from '../video/video'
import { VideoChannelModel } from '../video/video-channel'
import { VideoFileModel } from '../video/video-file'
{
fields: [ 'actorId' ]
},
+ {
+ fields: [ 'expiresOn' ]
+ },
{
fields: [ 'url' ],
unique: true
}
]
})
-export class VideoRedundancyModel extends Model {
+export class VideoRedundancyModel extends Model<Partial<AttributesOnly<VideoRedundancyModel>>> {
@CreatedAt
createdAt: Date
...this.buildVideoIdsForDuplication(peertubeActor)
},
include: [
- VideoRedundancyModel.buildServerRedundancyInclude()
+ VideoRedundancyModel.buildServerRedundancyInclude(),
+
+ // Required by publishedAt sort
+ {
+ model: ScheduleVideoUpdateModel.unscoped(),
+ required: false
+ }
]
}
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()