Add totalLocalVideoFilesSize in stats
This commit is contained in:
parent
3195cd1c11
commit
44b9c0ba31
|
@ -8,6 +8,7 @@ import { VideoCommentModel } from '../../../models/video/video-comment'
|
|||
import { VideoRedundancyModel } from '../../../models/redundancy/video-redundancy'
|
||||
import { CONFIG, ROUTE_CACHE_LIFETIME } from '../../../initializers/constants'
|
||||
import { cacheRoute } from '../../../middlewares/cache'
|
||||
import { VideoFileModel } from '../../../models/video/video-file'
|
||||
|
||||
const statsRouter = express.Router()
|
||||
|
||||
|
@ -16,11 +17,12 @@ statsRouter.get('/stats',
|
|||
asyncMiddleware(getStats)
|
||||
)
|
||||
|
||||
async function getStats (req: express.Request, res: express.Response, next: express.NextFunction) {
|
||||
async function getStats (req: express.Request, res: express.Response) {
|
||||
const { totalLocalVideos, totalLocalVideoViews, totalVideos } = await VideoModel.getStats()
|
||||
const { totalLocalVideoComments, totalVideoComments } = await VideoCommentModel.getStats()
|
||||
const { totalUsers } = await UserModel.getStats()
|
||||
const { totalInstanceFollowers, totalInstanceFollowing } = await ActorFollowModel.getStats()
|
||||
const { totalLocalVideoFilesSize } = await VideoFileModel.getStats()
|
||||
|
||||
const videosRedundancyStats = await Promise.all(
|
||||
CONFIG.REDUNDANCY.VIDEOS.STRATEGIES.map(r => {
|
||||
|
@ -32,8 +34,9 @@ async function getStats (req: express.Request, res: express.Response, next: expr
|
|||
const data: ServerStats = {
|
||||
totalLocalVideos,
|
||||
totalLocalVideoViews,
|
||||
totalVideos,
|
||||
totalLocalVideoFilesSize,
|
||||
totalLocalVideoComments,
|
||||
totalVideos,
|
||||
totalVideoComments,
|
||||
totalUsers,
|
||||
totalInstanceFollowers,
|
||||
|
|
|
@ -395,7 +395,7 @@ export class VideoRedundancyModel extends Model<VideoRedundancyModel> {
|
|||
]
|
||||
}
|
||||
|
||||
return VideoRedundancyModel.find(query as any) // FIXME: typings
|
||||
return VideoRedundancyModel.findOne(query as any) // FIXME: typings
|
||||
.then((r: any) => ({
|
||||
totalUsed: parseInt(r.totalUsed.toString(), 10),
|
||||
totalVideos: r.totalVideos,
|
||||
|
|
|
@ -120,6 +120,26 @@ export class VideoFileModel extends Model<VideoFileModel> {
|
|||
return VideoFileModel.findById(id, options)
|
||||
}
|
||||
|
||||
static async getStats () {
|
||||
let totalLocalVideoFilesSize = await VideoFileModel.sum('size', {
|
||||
include: [
|
||||
{
|
||||
attributes: [],
|
||||
model: VideoModel.unscoped(),
|
||||
where: {
|
||||
remote: false
|
||||
}
|
||||
}
|
||||
]
|
||||
} as any)
|
||||
// Sequelize could return null...
|
||||
if (!totalLocalVideoFilesSize) totalLocalVideoFilesSize = 0
|
||||
|
||||
return {
|
||||
totalLocalVideoFilesSize
|
||||
}
|
||||
}
|
||||
|
||||
hasSameUniqueKeysThan (other: VideoFileModel) {
|
||||
return this.fps === other.fps &&
|
||||
this.resolution === other.resolution &&
|
||||
|
|
|
@ -39,7 +39,7 @@ describe('Test stats (excluding redundancy)', function () {
|
|||
}
|
||||
await createUser(servers[0].url, servers[0].accessToken, user.username, user.password)
|
||||
|
||||
const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, {})
|
||||
const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { fixture: 'video_short.webm' })
|
||||
const videoUUID = resVideo.body.video.uuid
|
||||
|
||||
await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'comment')
|
||||
|
@ -60,6 +60,7 @@ describe('Test stats (excluding redundancy)', function () {
|
|||
expect(data.totalLocalVideoComments).to.equal(1)
|
||||
expect(data.totalLocalVideos).to.equal(1)
|
||||
expect(data.totalLocalVideoViews).to.equal(1)
|
||||
expect(data.totalLocalVideoFilesSize).to.equal(218910)
|
||||
expect(data.totalUsers).to.equal(2)
|
||||
expect(data.totalVideoComments).to.equal(1)
|
||||
expect(data.totalVideos).to.equal(1)
|
||||
|
|
|
@ -5,6 +5,7 @@ export interface ServerStats {
|
|||
totalLocalVideos: number
|
||||
totalLocalVideoViews: number
|
||||
totalLocalVideoComments: number
|
||||
totalLocalVideoFilesSize: number
|
||||
|
||||
totalVideos: number
|
||||
totalVideoComments: number
|
||||
|
|
Loading…
Reference in New Issue