Fix stat file size with HLS
This commit is contained in:
parent
c1961762b3
commit
0b84383d48
|
@ -269,10 +269,11 @@ export class VideoFileModel extends Model<VideoFileModel> {
|
||||||
}
|
}
|
||||||
|
|
||||||
static getStats () {
|
static getStats () {
|
||||||
const query: FindOptions = {
|
const webtorrentFilesQuery: FindOptions = {
|
||||||
include: [
|
include: [
|
||||||
{
|
{
|
||||||
attributes: [],
|
attributes: [],
|
||||||
|
required: true,
|
||||||
model: VideoModel.unscoped(),
|
model: VideoModel.unscoped(),
|
||||||
where: {
|
where: {
|
||||||
remote: false
|
remote: false
|
||||||
|
@ -281,10 +282,32 @@ export class VideoFileModel extends Model<VideoFileModel> {
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
return VideoFileModel.aggregate('size', 'SUM', query)
|
const hlsFilesQuery: FindOptions = {
|
||||||
.then(result => ({
|
include: [
|
||||||
totalLocalVideoFilesSize: parseAggregateResult(result)
|
{
|
||||||
}))
|
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
|
// Redefine upsert because sequelize does not use an appropriate where clause in the update query with 2 unique indexes
|
||||||
|
|
|
@ -1,24 +1,26 @@
|
||||||
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
||||||
|
|
||||||
import * as chai from 'chai'
|
|
||||||
import 'mocha'
|
import 'mocha'
|
||||||
import { ServerStats } from '../../../../shared/models/server/server-stats.model'
|
import * as chai from 'chai'
|
||||||
import {
|
import {
|
||||||
cleanupTests,
|
cleanupTests,
|
||||||
createUser,
|
createUser,
|
||||||
doubleFollow,
|
doubleFollow,
|
||||||
flushAndRunMultipleServers,
|
flushAndRunMultipleServers,
|
||||||
follow,
|
follow,
|
||||||
ServerInfo, unfollow,
|
ServerInfo,
|
||||||
|
unfollow,
|
||||||
|
updateCustomSubConfig,
|
||||||
uploadVideo,
|
uploadVideo,
|
||||||
|
userLogin,
|
||||||
viewVideo,
|
viewVideo,
|
||||||
wait,
|
wait
|
||||||
userLogin
|
|
||||||
} from '../../../../shared/extra-utils'
|
} from '../../../../shared/extra-utils'
|
||||||
import { setAccessTokensToServers } from '../../../../shared/extra-utils/index'
|
import { setAccessTokensToServers } from '../../../../shared/extra-utils/index'
|
||||||
|
import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
|
||||||
import { getStats } from '../../../../shared/extra-utils/server/stats'
|
import { getStats } from '../../../../shared/extra-utils/server/stats'
|
||||||
import { addVideoCommentThread } from '../../../../shared/extra-utils/videos/video-comments'
|
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
|
const expect = chai.expect
|
||||||
|
|
||||||
|
@ -31,7 +33,9 @@ describe('Test stats (excluding redundancy)', function () {
|
||||||
|
|
||||||
before(async function () {
|
before(async function () {
|
||||||
this.timeout(60000)
|
this.timeout(60000)
|
||||||
|
|
||||||
servers = await flushAndRunMultipleServers(3)
|
servers = await flushAndRunMultipleServers(3)
|
||||||
|
|
||||||
await setAccessTokensToServers(servers)
|
await setAccessTokensToServers(servers)
|
||||||
|
|
||||||
await doubleFollow(servers[0], servers[1])
|
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 () {
|
after(async function () {
|
||||||
await cleanupTests(servers)
|
await cleanupTests(servers)
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue