diff options
Diffstat (limited to 'server/models')
-rw-r--r-- | server/models/redundancy/video-redundancy.ts | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/server/models/redundancy/video-redundancy.ts b/server/models/redundancy/video-redundancy.ts index b7454c617..6ae02efb9 100644 --- a/server/models/redundancy/video-redundancy.ts +++ b/server/models/redundancy/video-redundancy.ts | |||
@@ -245,6 +245,37 @@ export class VideoRedundancyModel extends Model<VideoRedundancyModel> { | |||
245 | .findAll(query) | 245 | .findAll(query) |
246 | } | 246 | } |
247 | 247 | ||
248 | static async getStats (strategy: VideoRedundancyStrategy) { | ||
249 | const actor = await getServerActor() | ||
250 | |||
251 | const query = { | ||
252 | raw: true, | ||
253 | attributes: [ | ||
254 | [ Sequelize.fn('COALESCE', Sequelize.fn('SUM', Sequelize.col('VideoFile.size')), '0'), 'totalUsed' ], | ||
255 | [ Sequelize.fn('COUNT', Sequelize.fn('DISTINCT', 'videoId')), 'totalVideos' ], | ||
256 | [ Sequelize.fn('COUNT', 'videoFileId'), 'totalVideoFiles' ] | ||
257 | ], | ||
258 | where: { | ||
259 | strategy, | ||
260 | actorId: actor.id | ||
261 | }, | ||
262 | include: [ | ||
263 | { | ||
264 | attributes: [], | ||
265 | model: VideoFileModel, | ||
266 | required: true | ||
267 | } | ||
268 | ] | ||
269 | } | ||
270 | |||
271 | return VideoRedundancyModel.find(query as any) // FIXME: typings | ||
272 | .then((r: any) => ({ | ||
273 | totalUsed: parseInt(r.totalUsed.toString(), 10), | ||
274 | totalVideos: r.totalVideos, | ||
275 | totalVideoFiles: r.totalVideoFiles | ||
276 | })) | ||
277 | } | ||
278 | |||
248 | toActivityPubObject (): CacheFileObject { | 279 | toActivityPubObject (): CacheFileObject { |
249 | return { | 280 | return { |
250 | id: this.url, | 281 | id: this.url, |