1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-06 03:50:26 +02:00

Add abuse and registration requests stats

This commit is contained in:
Chocobozzz 2024-02-21 13:48:52 +01:00
parent fbe47a9f8e
commit db69d9491e
No known key found for this signature in database
GPG key ID: 583A612D890159BE
25 changed files with 638 additions and 227 deletions

View file

@ -1,4 +1,4 @@
import { abusePredefinedReasonsMap } from '@peertube/peertube-core-utils'
import { abusePredefinedReasonsMap, forceNumber } from '@peertube/peertube-core-utils'
import {
AbuseFilter,
AbuseObject,
@ -41,7 +41,7 @@ import {
MUserAccountId
} from '../../types/models/index.js'
import { AccountModel, ScopeNames as AccountScopeNames, SummaryOptions as AccountSummaryOptions } from '../account/account.js'
import { getSort, throwIfNotValid } from '../shared/index.js'
import { getSort, parseAggregateResult, throwIfNotValid } from '../shared/index.js'
import { ThumbnailModel } from '../video/thumbnail.js'
import { VideoBlacklistModel } from '../video/video-blacklist.js'
import { SummaryOptions as ChannelSummaryOptions, VideoChannelModel, ScopeNames as VideoChannelScopeNames } from '../video/video-channel.js'
@ -220,6 +220,10 @@ export class AbuseModel extends Model<Partial<AttributesOnly<AbuseModel>>> {
@Column(DataType.ARRAY(DataType.INTEGER))
predefinedReasons: AbusePredefinedReasonsType[]
@AllowNull(true)
@Column
processedAt: Date
@CreatedAt
createdAt: Date
@ -441,6 +445,35 @@ export class AbuseModel extends Model<Partial<AttributesOnly<AbuseModel>>> {
return { total, data }
}
// ---------------------------------------------------------------------------
static getStats () {
const query = `SELECT ` +
`AVG(EXTRACT(EPOCH FROM ("processedAt" - "createdAt") * 1000)) ` +
`FILTER (WHERE "processedAt" IS NOT NULL AND "createdAt" > CURRENT_DATE - INTERVAL '3 months')` +
`AS "avgResponseTime", ` +
`COUNT(*) FILTER (WHERE "processedAt" IS NOT NULL) AS "processedAbuses", ` +
`COUNT(*) AS "totalAbuses" ` +
`FROM "abuse"`
return AbuseModel.sequelize.query<any>(query, {
type: QueryTypes.SELECT,
raw: true
}).then(([ row ]) => {
return {
totalAbuses: parseAggregateResult(row.totalAbuses),
totalAbusesProcessed: parseAggregateResult(row.processedAbuses),
averageAbuseResponseTimeMs: row?.avgResponseTime
? forceNumber(row.avgResponseTime)
: null
}
})
}
// ---------------------------------------------------------------------------
buildBaseVideoCommentAbuse (this: MAbuseUserFormattable) {
// Associated video comment could have been destroyed if the video has been deleted
if (!this.VideoCommentAbuse?.VideoComment) return null