Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Fix abuse/registration requests stats

Chocobozzz2e760485c159
diff --git a/server/core/models/abuse/abuse.ts b/server/core/models/abuse/abuse.ts
index c3b03b18d0..530eb09df2 100644
--- a/server/core/models/abuse/abuse.ts
+++ b/server/core/models/abuse/abuse.ts
@@ -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"`
diff --git a/server/core/models/user/user-registration.ts b/server/core/models/user/user-registration.ts
index 54245b009b..64ff04c35c 100644
--- a/server/core/models/user/user-registration.ts
+++ b/server/core/models/user/user-registration.ts
@@ -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"`