Fix abuse/registration requests stats

With old abuses/registration requests that do not have the processedAt
attribute set
pull/6266/head
Chocobozzz 2024-02-27 15:26:37 +01:00
parent b6b1aaa56f
commit 2e760485c1
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
2 changed files with 7 additions and 4 deletions

View File

@ -10,7 +10,8 @@ import {
AdminVideoCommentAbuse,
UserAbuse,
UserVideoAbuse,
type AbuseStateType
type AbuseStateType,
AbuseState
} from '@peertube/peertube-models'
import { isAbuseModerationCommentValid, isAbuseReasonValid, isAbuseStateValid } from '@server/helpers/custom-validators/abuses.js'
import invert from 'lodash-es/invert.js'
@ -449,7 +450,8 @@ export class AbuseModel extends SequelizeModel<AbuseModel> {
`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", ` +
// "processedAt" has been introduced in PeerTube 6.1 so also check the abuse state to check processed abuses
`COUNT(*) FILTER (WHERE "processedAt" IS NOT NULL OR "state" != ${AbuseState.PENDING}) AS "processedAbuses", ` +
`COUNT(*) AS "totalAbuses" ` +
`FROM "abuse"`

View File

@ -1,4 +1,4 @@
import { UserRegistration, type UserRegistrationStateType } from '@peertube/peertube-models'
import { UserRegistration, UserRegistrationState, type UserRegistrationStateType } from '@peertube/peertube-models'
import {
isRegistrationModerationResponseValid,
isRegistrationReasonValid,
@ -234,7 +234,8 @@ export class UserRegistrationModel extends SequelizeModel<UserRegistrationModel>
`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 "processedRequests", ` +
// "processedAt" has been introduced in PeerTube 6.1 so also check the abuse state to check processed abuses
`COUNT(*) FILTER (WHERE "processedAt" IS NOT NULL OR "state" != ${UserRegistrationState.PENDING}) AS "processedRequests", ` +
`COUNT(*) AS "totalRequests" ` +
`FROM "userRegistration"`