mirror of https://github.com/Chocobozzz/PeerTube
Fix total videos stats
parent
8c966daab3
commit
baab47ca81
|
@ -26,11 +26,12 @@ async function getStats (req: express.Request, res: express.Response) {
|
||||||
const { totalInstanceFollowers, totalInstanceFollowing } = await ActorFollowModel.getStats()
|
const { totalInstanceFollowers, totalInstanceFollowing } = await ActorFollowModel.getStats()
|
||||||
const { totalLocalVideoFilesSize } = await VideoFileModel.getStats()
|
const { totalLocalVideoFilesSize } = await VideoFileModel.getStats()
|
||||||
|
|
||||||
const strategies: { strategy: VideoRedundancyStrategyWithManual, size: number }[] = CONFIG.REDUNDANCY.VIDEOS.STRATEGIES
|
const strategies = CONFIG.REDUNDANCY.VIDEOS.STRATEGIES
|
||||||
.map(r => ({
|
.map(r => ({
|
||||||
strategy: r.strategy,
|
strategy: r.strategy as VideoRedundancyStrategyWithManual,
|
||||||
size: r.size
|
size: r.size
|
||||||
}))
|
}))
|
||||||
|
|
||||||
strategies.push({ strategy: 'manual', size: null })
|
strategies.push({ strategy: 'manual', size: null })
|
||||||
|
|
||||||
const videosRedundancyStats = await Promise.all(
|
const videosRedundancyStats = await Promise.all(
|
||||||
|
|
|
@ -125,6 +125,7 @@ import { VideoFile } from '@shared/models/videos/video-file.model'
|
||||||
import { getHLSDirectory, getTorrentFileName, getTorrentFilePath, getVideoFilename, getVideoFilePath } from '@server/lib/video-paths'
|
import { getHLSDirectory, getTorrentFileName, getTorrentFilePath, getVideoFilename, getVideoFilePath } from '@server/lib/video-paths'
|
||||||
import { ModelCache } from '@server/models/model-cache'
|
import { ModelCache } from '@server/models/model-cache'
|
||||||
import { buildListQuery, BuildVideosQueryOptions, wrapForAPIResults } from './video-query-builder'
|
import { buildListQuery, BuildVideosQueryOptions, wrapForAPIResults } from './video-query-builder'
|
||||||
|
import { buildNSFWFilter } from '@server/helpers/express-utils'
|
||||||
|
|
||||||
export enum ScopeNames {
|
export enum ScopeNames {
|
||||||
AVAILABLE_FOR_LIST_IDS = 'AVAILABLE_FOR_LIST_IDS',
|
AVAILABLE_FOR_LIST_IDS = 'AVAILABLE_FOR_LIST_IDS',
|
||||||
|
@ -1301,16 +1302,25 @@ export class VideoModel extends Model<VideoModel> {
|
||||||
remote: false
|
remote: false
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
const totalVideos = await VideoModel.count()
|
|
||||||
|
|
||||||
let totalLocalVideoViews = await VideoModel.sum('views', {
|
let totalLocalVideoViews = await VideoModel.sum('views', {
|
||||||
where: {
|
where: {
|
||||||
remote: false
|
remote: false
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// Sequelize could return null...
|
// Sequelize could return null...
|
||||||
if (!totalLocalVideoViews) totalLocalVideoViews = 0
|
if (!totalLocalVideoViews) totalLocalVideoViews = 0
|
||||||
|
|
||||||
|
const { total: totalVideos } = await VideoModel.listForApi({
|
||||||
|
start: 0,
|
||||||
|
count: 0,
|
||||||
|
sort: '-publishedAt',
|
||||||
|
nsfw: buildNSFWFilter(),
|
||||||
|
includeLocalVideos: true,
|
||||||
|
withFiles: false
|
||||||
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
totalLocalVideos,
|
totalLocalVideos,
|
||||||
totalLocalVideoViews,
|
totalLocalVideoViews,
|
||||||
|
@ -1419,6 +1429,8 @@ export class VideoModel extends Model<VideoModel> {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getModels () {
|
function getModels () {
|
||||||
|
if (options.count === 0) return Promise.resolve([])
|
||||||
|
|
||||||
const { query, replacements, order } = buildListQuery(VideoModel, options)
|
const { query, replacements, order } = buildListQuery(VideoModel, options)
|
||||||
const queryModels = wrapForAPIResults(query, replacements, options, order)
|
const queryModels = wrapForAPIResults(query, replacements, options, order)
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ import {
|
||||||
doubleFollow,
|
doubleFollow,
|
||||||
flushAndRunMultipleServers,
|
flushAndRunMultipleServers,
|
||||||
follow,
|
follow,
|
||||||
ServerInfo,
|
ServerInfo, unfollow,
|
||||||
uploadVideo,
|
uploadVideo,
|
||||||
viewVideo,
|
viewVideo,
|
||||||
wait
|
wait
|
||||||
|
@ -95,6 +95,16 @@ describe('Test stats (excluding redundancy)', function () {
|
||||||
expect(data.totalInstanceFollowers).to.equal(0)
|
expect(data.totalInstanceFollowers).to.equal(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('Should have the correct total videos stats after an unfollow', async function () {
|
||||||
|
await unfollow(servers[2].url, servers[2].accessToken, servers[0])
|
||||||
|
await waitJobs(servers)
|
||||||
|
|
||||||
|
const res = await getStats(servers[2].url)
|
||||||
|
const data: ServerStats = res.body
|
||||||
|
|
||||||
|
expect(data.totalVideos).to.equal(0)
|
||||||
|
})
|
||||||
|
|
||||||
after(async function () {
|
after(async function () {
|
||||||
await cleanupTests(servers)
|
await cleanupTests(servers)
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue