aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2020-04-20 15:15:10 +0200
committerRigel Kent <par@rigelk.eu>2020-05-01 16:41:02 +0200
commitefa012edad6b9b4c38a21a5c7d06ce0f7089d22c (patch)
treeeb80dcf50e2eb745c223f4f40a4a76bdbada0f7b /server
parent0251197e249cc03b65805ed6805da72bf4573529 (diff)
downloadPeerTube-efa012edad6b9b4c38a21a5c7d06ce0f7089d22c.tar.gz
PeerTube-efa012edad6b9b4c38a21a5c7d06ce0f7089d22c.tar.zst
PeerTube-efa012edad6b9b4c38a21a5c7d06ce0f7089d22c.zip
Add reportee stats for deleted videos
Diffstat (limited to 'server')
-rw-r--r--server/models/video/video-abuse.ts43
1 files changed, 35 insertions, 8 deletions
diff --git a/server/models/video/video-abuse.ts b/server/models/video/video-abuse.ts
index 71b519cd9..285fb1fbc 100644
--- a/server/models/video/video-abuse.ts
+++ b/server/models/video/video-abuse.ts
@@ -15,7 +15,7 @@ import { VideoAbuseState, VideoDetails } from '../../../shared'
15import { CONSTRAINTS_FIELDS, VIDEO_ABUSE_STATES } from '../../initializers/constants' 15import { CONSTRAINTS_FIELDS, VIDEO_ABUSE_STATES } from '../../initializers/constants'
16import { MUserAccountId, MVideoAbuse, MVideoAbuseFormattable, MVideoAbuseVideo } from '../../typings/models' 16import { MUserAccountId, MVideoAbuse, MVideoAbuseFormattable, MVideoAbuseVideo } from '../../typings/models'
17import * as Bluebird from 'bluebird' 17import * as Bluebird from 'bluebird'
18import { literal, Op, Sequelize } from 'sequelize' 18import { literal, Op } from 'sequelize'
19import { ThumbnailModel } from './thumbnail' 19import { ThumbnailModel } from './thumbnail'
20import { VideoBlacklistModel } from './video-blacklist' 20import { VideoBlacklistModel } from './video-blacklist'
21import { ScopeNames as VideoChannelScopeNames, SummaryOptions, VideoChannelModel } from './video-channel' 21import { ScopeNames as VideoChannelScopeNames, SummaryOptions, VideoChannelModel } from './video-channel'
@@ -75,6 +75,7 @@ export enum ScopeNames {
75 attributes: { 75 attributes: {
76 include: [ 76 include: [
77 [ 77 [
78 // we don't care about this count for deleted videos, so there are not included
78 literal( 79 literal(
79 '(' + 80 '(' +
80 'SELECT count(*) ' + 81 'SELECT count(*) ' +
@@ -85,6 +86,7 @@ export enum ScopeNames {
85 'countReportsForVideo' 86 'countReportsForVideo'
86 ], 87 ],
87 [ 88 [
89 // we don't care about this count for deleted videos, so there are not included
88 literal( 90 literal(
89 '(' + 91 '(' +
90 'SELECT t.nth ' + 92 'SELECT t.nth ' +
@@ -109,7 +111,17 @@ export enum ScopeNames {
109 'WHERE "account"."id" = "VideoAbuseModel"."reporterAccountId" ' + 111 'WHERE "account"."id" = "VideoAbuseModel"."reporterAccountId" ' +
110 ')' 112 ')'
111 ), 113 ),
112 'countReportsForReporter' 114 'countReportsForReporter__video'
115 ],
116 [
117 literal(
118 '(' +
119 'SELECT count(DISTINCT "videoAbuse"."id") ' +
120 'FROM "videoAbuse" ' +
121 `WHERE CAST("deletedVideo"->'channel'->'ownerAccount'->>'id' AS INTEGER) = "VideoAbuseModel"."reporterAccountId" ` +
122 ')'
123 ),
124 'countReportsForReporter__deletedVideo'
113 ], 125 ],
114 [ 126 [
115 literal( 127 literal(
@@ -118,10 +130,23 @@ export enum ScopeNames {
118 'FROM "videoAbuse" ' + 130 'FROM "videoAbuse" ' +
119 'INNER JOIN "video" ON "video"."id" = "videoAbuse"."videoId" ' + 131 'INNER JOIN "video" ON "video"."id" = "videoAbuse"."videoId" ' +
120 'INNER JOIN "videoChannel" ON "videoChannel"."id" = "video"."channelId" ' + 132 'INNER JOIN "videoChannel" ON "videoChannel"."id" = "video"."channelId" ' +
121 'INNER JOIN "account" ON "videoChannel"."accountId" = "Video->VideoChannel"."accountId" ' + 133 'INNER JOIN "account" ON ' +
134 '"videoChannel"."accountId" = "Video->VideoChannel"."accountId" ' +
135 `OR "videoChannel"."accountId" = CAST("VideoAbuseModel"."deletedVideo"->'channel'->'ownerAccount'->>'id' AS INTEGER) ` +
136 ')'
137 ),
138 'countReportsForReportee__video'
139 ],
140 [
141 literal(
142 '(' +
143 'SELECT count(DISTINCT "videoAbuse"."id") ' +
144 'FROM "videoAbuse" ' +
145 `WHERE CAST("deletedVideo"->'channel'->'ownerAccount'->>'id' AS INTEGER) = "Video->VideoChannel"."accountId" ` +
146 `OR CAST("deletedVideo"->'channel'->'ownerAccount'->>'id' AS INTEGER) = CAST("VideoAbuseModel"."deletedVideo"->'channel'->'ownerAccount'->>'id' AS INTEGER) ` +
122 ')' 147 ')'
123 ), 148 ),
124 'countReportsForReportee' 149 'countReportsForReportee__deletedVideo'
125 ] 150 ]
126 ] 151 ]
127 }, 152 },
@@ -270,8 +295,10 @@ export class VideoAbuseModel extends Model<VideoAbuseModel> {
270 toFormattedJSON (this: MVideoAbuseFormattable): VideoAbuse { 295 toFormattedJSON (this: MVideoAbuseFormattable): VideoAbuse {
271 const countReportsForVideo = this.get('countReportsForVideo') as number 296 const countReportsForVideo = this.get('countReportsForVideo') as number
272 const nthReportForVideo = this.get('nthReportForVideo') as number 297 const nthReportForVideo = this.get('nthReportForVideo') as number
273 const countReportsForReporter = this.get('countReportsForReporter') as number 298 const countReportsForReporterVideo = this.get('countReportsForReporter__video') as number
274 const countReportsForReportee = this.get('countReportsForReportee') as number 299 const countReportsForReporterDeletedVideo = this.get('countReportsForReporter__deletedVideo') as number
300 const countReportsForReporteeVideo = this.get('countReportsForReportee__video') as number
301 const countReportsForReporteeDeletedVideo = this.get('countReportsForReportee__deletedVideo') as number
275 302
276 const video = this.Video 303 const video = this.Video
277 ? this.Video 304 ? this.Video
@@ -300,8 +327,8 @@ export class VideoAbuseModel extends Model<VideoAbuseModel> {
300 updatedAt: this.updatedAt, 327 updatedAt: this.updatedAt,
301 count: countReportsForVideo || 0, 328 count: countReportsForVideo || 0,
302 nth: nthReportForVideo || 0, 329 nth: nthReportForVideo || 0,
303 countReportsForReporter: countReportsForReporter || 0, 330 countReportsForReporter: (countReportsForReporterVideo || 0) + (countReportsForReporterDeletedVideo || 0),
304 countReportsForReportee: countReportsForReportee || 0 331 countReportsForReportee: (countReportsForReporteeVideo || 0) + (countReportsForReporteeDeletedVideo || 0)
305 } 332 }
306 } 333 }
307 334