aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/redundancy
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-09-14 14:57:59 +0200
committerChocobozzz <me@florianbigard.com>2018-09-14 14:57:59 +0200
commit4b5384f6e7be62d072d21d8d964951ba572ab10e (patch)
tree64dbd0c55096435ef804988c4750f717ad140633 /server/models/redundancy
parentcfc16a6db88378f83fa3a501170fa0fc5e7d6636 (diff)
downloadPeerTube-4b5384f6e7be62d072d21d8d964951ba572ab10e.tar.gz
PeerTube-4b5384f6e7be62d072d21d8d964951ba572ab10e.tar.zst
PeerTube-4b5384f6e7be62d072d21d8d964951ba572ab10e.zip
Add redundancy stats
Diffstat (limited to 'server/models/redundancy')
-rw-r--r--server/models/redundancy/video-redundancy.ts31
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,