diff --git a/server/core/models/abuse/abuse.ts b/server/core/models/abuse/abuse.ts index 530eb09df..5f57868ef 100644 --- a/server/core/models/abuse/abuse.ts +++ b/server/core/models/abuse/abuse.ts @@ -74,7 +74,8 @@ export enum ScopeNames { '(' + 'SELECT count(*) ' + 'FROM "videoAbuse" ' + - 'WHERE "videoId" = "VideoAbuse"."videoId" AND "videoId" IS NOT NULL' + + 'WHERE "videoId" IN (SELECT "videoId" FROM "videoAbuse" WHERE "abuseId" = "AbuseModel"."id") ' + + 'AND "videoId" IS NOT NULL' + ')' ), 'countReportsForVideo' @@ -85,11 +86,10 @@ export enum ScopeNames { '(' + 'SELECT t.nth ' + 'FROM ( ' + - 'SELECT id, ' + - 'row_number() OVER (PARTITION BY "videoId" ORDER BY "createdAt") AS nth ' + + 'SELECT id, "abuseId", row_number() OVER (PARTITION BY "videoId" ORDER BY "createdAt") AS nth ' + 'FROM "videoAbuse" ' + ') t ' + - 'WHERE t.id = "VideoAbuse".id AND t.id IS NOT NULL' + + 'WHERE t."abuseId" = "AbuseModel"."id" ' + ')' ), 'nthReportForVideo' @@ -645,7 +645,8 @@ export class AbuseModel extends SequelizeModel { id: { [Op.in]: ids } - } + }, + limit: parameters.count }) }