Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Fix stat file size with HLS

Chocobozzz0b84383d488f
diff --git a/server/models/video/video-file.ts b/server/models/video/video-file.ts
index a130317f6e..d48c9f5d4d 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> {
}
static getStats () {
- const query: FindOptions = {
+ const webtorrentFilesQuery: FindOptions = {
include: [
{
attributes: [],
+ required: true,
model: VideoModel.unscoped(),
where: {
remote: false
@@ -281,10 +282,32 @@ export class VideoFileModel extends Model<VideoFileModel> {
]
}
- return VideoFileModel.aggregate('size', 'SUM', query)
- .then(result => ({
- totalLocalVideoFilesSize: parseAggregateResult(result)
- }))
+ const hlsFilesQuery: FindOptions = {
+ include: [
+ {
+ attributes: [],
+ required: true,
+ model: VideoStreamingPlaylistModel.unscoped(),
+ include: [
+ {
+ attributes: [],
+ model: VideoModel.unscoped(),
+ required: true,
+ where: {
+ remote: false
+ }
+ }
+ ]
+ }
+ ]
+ }
+
+ return Promise.all([
+ VideoFileModel.aggregate('size', 'SUM', webtorrentFilesQuery),
+ VideoFileModel.aggregate('size', 'SUM', hlsFilesQuery)
+ ]).then(([ webtorrentResult, hlsResult ]) => ({
+ totalLocalVideoFilesSize: parseAggregateResult(webtorrentResult) + parseAggregateResult(hlsResult)
+ }))
}
// 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 637525ff8c..0e77712cf7 100644
--- a/server/tests/api/server/stats.ts
+++ b/server/tests/api/server/stats.ts
@@ -1,24 +1,26 @@
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
-import * as chai from 'chai'
import 'mocha'
-import { ServerStats } from '../../../../shared/models/server/server-stats.model'
+import * as chai from 'chai'
import {
cleanupTests,
createUser,
doubleFollow,
flushAndRunMultipleServers,
follow,
- ServerInfo, unfollow,
+ ServerInfo,
+ unfollow,
+ updateCustomSubConfig,
uploadVideo,
+ userLogin,
viewVideo,
- wait,
- userLogin
+ wait
} from '../../../../shared/extra-utils'
import { setAccessTokensToServers } from '../../../../shared/extra-utils/index'
+import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
import { getStats } from '../../../../shared/extra-utils/server/stats'
import { addVideoCommentThread } from '../../../../shared/extra-utils/videos/video-comments'
-import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
+import { ServerStats } from '../../../../shared/models/server/server-stats.model'
const expect = chai.expect
@@ -31,7 +33,9 @@ describe('Test stats (excluding redundancy)', function () {
before(async function () {
this.timeout(60000)
+
servers = await flushAndRunMultipleServers(3)
+
await setAccessTokensToServers(servers)
await doubleFollow(servers[0], servers[1])
@@ -130,6 +134,48 @@ describe('Test stats (excluding redundancy)', function () {
}
})
+ it('Should correctly count video file sizes if transcoding is enabled', async function () {
+ this.timeout(20000)
+
+ await updateCustomSubConfig(servers[0].url, servers[0].accessToken, {
+ transcoding: {
+ enabled: true,
+ webtorrent: {
+ enabled: true
+ },
+ hls: {
+ enabled: true
+ },
+ resolutions: {
+ '0p': false,
+ '240p': false,
+ '360p': false,
+ '480p': false,
+ '720p': false,
+ '1080p': false,
+ '2160p': false
+ }
+ }
+ })
+
+ await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video', fixture: 'video_short.webm' })
+
+ await waitJobs(servers)
+
+ {
+ const res = await getStats(servers[1].url)
+ const data: ServerStats = res.body
+ expect(data.totalLocalVideoFilesSize).to.equal(0)
+ }
+
+ {
+ const res = await getStats(servers[0].url)
+ const data: ServerStats = res.body
+ expect(data.totalLocalVideoFilesSize).to.be.greaterThan(300000)
+ expect(data.totalLocalVideoFilesSize).to.be.lessThan(400000)
+ }
+ })
+
after(async function () {
await cleanupTests(servers)
})