+ ],
+ where: videoFilterWhere
+ }
+
+ // /!\ On video model /!\
+ const countOptions = {
+ where: videoFilterWhere
+ }
+
+ return Promise.all([
+ VideoModel.findAll(findOptions),
+
+ VideoModel.count(countOptions)
+ ]).then(([ data, total ]) => ({ total, data }))
+ }
+
+ static async getStats (strategy: VideoRedundancyStrategyWithManual) {
+ const actor = await getServerActor()
+
+ const sql = `WITH "tmp" AS ` +
+ `(` +
+ `SELECT "videoFile"."size" AS "videoFileSize", "videoStreamingFile"."size" AS "videoStreamingFileSize", ` +
+ `"videoFile"."videoId" AS "videoFileVideoId", "videoStreamingPlaylist"."videoId" AS "videoStreamingVideoId"` +
+ `FROM "videoRedundancy" AS "videoRedundancy" ` +
+ `LEFT JOIN "videoFile" AS "videoFile" ON "videoRedundancy"."videoFileId" = "videoFile"."id" ` +
+ `LEFT JOIN "videoStreamingPlaylist" ON "videoRedundancy"."videoStreamingPlaylistId" = "videoStreamingPlaylist"."id" ` +
+ `LEFT JOIN "videoFile" AS "videoStreamingFile" ` +
+ `ON "videoStreamingPlaylist"."id" = "videoStreamingFile"."videoStreamingPlaylistId" ` +
+ `WHERE "videoRedundancy"."strategy" = :strategy AND "videoRedundancy"."actorId" = :actorId` +
+ `), ` +
+ `"videoIds" AS (` +
+ `SELECT "videoFileVideoId" AS "videoId" FROM "tmp" ` +
+ `UNION SELECT "videoStreamingVideoId" AS "videoId" FROM "tmp" ` +
+ `) ` +
+ `SELECT ` +
+ `COALESCE(SUM("videoFileSize"), '0') + COALESCE(SUM("videoStreamingFileSize"), '0') AS "totalUsed", ` +
+ `(SELECT COUNT("videoIds"."videoId") FROM "videoIds") AS "totalVideos", ` +
+ `COUNT(*) AS "totalVideoFiles" ` +
+ `FROM "tmp"`
+
+ return VideoRedundancyModel.sequelize.query<any>(sql, {
+ replacements: { strategy, actorId: actor.id },
+ type: QueryTypes.SELECT
+ }).then(([ row ]) => ({
+ totalUsed: parseAggregateResult(row.totalUsed),
+ totalVideos: row.totalVideos,
+ totalVideoFiles: row.totalVideoFiles
+ }))
+ }
+
+ static toFormattedJSONStatic (video: MVideoForRedundancyAPI): VideoRedundancy {
+ const filesRedundancies: FileRedundancyInformation[] = []
+ const streamingPlaylistsRedundancies: StreamingPlaylistRedundancyInformation[] = []
+
+ for (const file of video.VideoFiles) {
+ for (const redundancy of file.RedundancyVideos) {
+ filesRedundancies.push({
+ id: redundancy.id,
+ fileUrl: redundancy.fileUrl,
+ strategy: redundancy.strategy,
+ createdAt: redundancy.createdAt,
+ updatedAt: redundancy.updatedAt,
+ expiresOn: redundancy.expiresOn,
+ size: file.size
+ })
+ }