aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-11-10 08:07:21 +0100
committerChocobozzz <me@florianbigard.com>2020-11-10 08:07:21 +0100
commit0b84383d488facc321b100f3280a872ee53e888b (patch)
tree8d6676ca07851adb35311597ee2b1bb6978f6c00 /server
parentc1961762b31567057e32eb7432a6995a4a81075c (diff)
downloadPeerTube-0b84383d488facc321b100f3280a872ee53e888b.tar.gz
PeerTube-0b84383d488facc321b100f3280a872ee53e888b.tar.zst
PeerTube-0b84383d488facc321b100f3280a872ee53e888b.zip
Fix stat file size with HLS
Diffstat (limited to 'server')
-rw-r--r--server/models/video/video-file.ts33
-rw-r--r--server/tests/api/server/stats.ts58
2 files changed, 80 insertions, 11 deletions
diff --git a/server/models/video/video-file.ts b/server/models/video/video-file.ts
index a130317f6..d48c9f5d4 100644
--- a/server/models/video/video-file.ts
+++ b/server/models/video/video-file.ts
@@ -269,10 +269,11 @@ export class VideoFileModel extends Model<VideoFileModel> {
269 } 269 }
270 270
271 static getStats () { 271 static getStats () {
272 const query: FindOptions = { 272 const webtorrentFilesQuery: FindOptions = {
273 include: [ 273 include: [
274 { 274 {
275 attributes: [], 275 attributes: [],
276 required: true,
276 model: VideoModel.unscoped(), 277 model: VideoModel.unscoped(),
277 where: { 278 where: {
278 remote: false 279 remote: false
@@ -281,10 +282,32 @@ export class VideoFileModel extends Model<VideoFileModel> {
281 ] 282 ]
282 } 283 }
283 284
284 return VideoFileModel.aggregate('size', 'SUM', query) 285 const hlsFilesQuery: FindOptions = {
285 .then(result => ({ 286 include: [
286 totalLocalVideoFilesSize: parseAggregateResult(result) 287 {
287 })) 288 attributes: [],
289 required: true,
290 model: VideoStreamingPlaylistModel.unscoped(),
291 include: [
292 {
293 attributes: [],
294 model: VideoModel.unscoped(),
295 required: true,
296 where: {
297 remote: false
298 }
299 }
300 ]
301 }
302 ]
303 }
304
305 return Promise.all([
306 VideoFileModel.aggregate('size', 'SUM', webtorrentFilesQuery),
307 VideoFileModel.aggregate('size', 'SUM', hlsFilesQuery)
308 ]).then(([ webtorrentResult, hlsResult ]) => ({
309 totalLocalVideoFilesSize: parseAggregateResult(webtorrentResult) + parseAggregateResult(hlsResult)
310 }))
288 } 311 }
289 312
290 // Redefine upsert because sequelize does not use an appropriate where clause in the update query with 2 unique indexes 313 // Redefine upsert because sequelize does not use an appropriate where clause in the update query with 2 unique indexes
diff --git a/server/tests/api/server/stats.ts b/server/tests/api/server/stats.ts
index 637525ff8..0e77712cf 100644
--- a/server/tests/api/server/stats.ts
+++ b/server/tests/api/server/stats.ts
@@ -1,24 +1,26 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import * as chai from 'chai'
4import 'mocha' 3import 'mocha'
5import { ServerStats } from '../../../../shared/models/server/server-stats.model' 4import * as chai from 'chai'
6import { 5import {
7 cleanupTests, 6 cleanupTests,
8 createUser, 7 createUser,
9 doubleFollow, 8 doubleFollow,
10 flushAndRunMultipleServers, 9 flushAndRunMultipleServers,
11 follow, 10 follow,
12 ServerInfo, unfollow, 11 ServerInfo,
12 unfollow,
13 updateCustomSubConfig,
13 uploadVideo, 14 uploadVideo,
15 userLogin,
14 viewVideo, 16 viewVideo,
15 wait, 17 wait
16 userLogin
17} from '../../../../shared/extra-utils' 18} from '../../../../shared/extra-utils'
18import { setAccessTokensToServers } from '../../../../shared/extra-utils/index' 19import { setAccessTokensToServers } from '../../../../shared/extra-utils/index'
20import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
19import { getStats } from '../../../../shared/extra-utils/server/stats' 21import { getStats } from '../../../../shared/extra-utils/server/stats'
20import { addVideoCommentThread } from '../../../../shared/extra-utils/videos/video-comments' 22import { addVideoCommentThread } from '../../../../shared/extra-utils/videos/video-comments'
21import { waitJobs } from '../../../../shared/extra-utils/server/jobs' 23import { ServerStats } from '../../../../shared/models/server/server-stats.model'
22 24
23const expect = chai.expect 25const expect = chai.expect
24 26
@@ -31,7 +33,9 @@ describe('Test stats (excluding redundancy)', function () {
31 33
32 before(async function () { 34 before(async function () {
33 this.timeout(60000) 35 this.timeout(60000)
36
34 servers = await flushAndRunMultipleServers(3) 37 servers = await flushAndRunMultipleServers(3)
38
35 await setAccessTokensToServers(servers) 39 await setAccessTokensToServers(servers)
36 40
37 await doubleFollow(servers[0], servers[1]) 41 await doubleFollow(servers[0], servers[1])
@@ -130,6 +134,48 @@ describe('Test stats (excluding redundancy)', function () {
130 } 134 }
131 }) 135 })
132 136
137 it('Should correctly count video file sizes if transcoding is enabled', async function () {
138 this.timeout(20000)
139
140 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, {
141 transcoding: {
142 enabled: true,
143 webtorrent: {
144 enabled: true
145 },
146 hls: {
147 enabled: true
148 },
149 resolutions: {
150 '0p': false,
151 '240p': false,
152 '360p': false,
153 '480p': false,
154 '720p': false,
155 '1080p': false,
156 '2160p': false
157 }
158 }
159 })
160
161 await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video', fixture: 'video_short.webm' })
162
163 await waitJobs(servers)
164
165 {
166 const res = await getStats(servers[1].url)
167 const data: ServerStats = res.body
168 expect(data.totalLocalVideoFilesSize).to.equal(0)
169 }
170
171 {
172 const res = await getStats(servers[0].url)
173 const data: ServerStats = res.body
174 expect(data.totalLocalVideoFilesSize).to.be.greaterThan(300000)
175 expect(data.totalLocalVideoFilesSize).to.be.lessThan(400000)
176 }
177 })
178
133 after(async function () { 179 after(async function () {
134 await cleanupTests(servers) 180 await cleanupTests(servers)
135 }) 181 })