X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fvideo%2Fvideo-comment.ts;h=de27b3d875fb3745682f5a056405162b5298f85f;hb=97816649b793bdd0f3df64631ae0ef7cf3d7461c;hp=1d5c7280df284b3cbccf32ba7dad3bacb919ea71;hpb=594d3e48d8a887bbf48ce4cc594c1c36c9640fb1;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/video/video-comment.ts b/server/models/video/video-comment.ts index 1d5c7280d..de27b3d87 100644 --- a/server/models/video/video-comment.ts +++ b/server/models/video/video-comment.ts @@ -1,6 +1,6 @@ import * as Bluebird from 'bluebird' import { uniq } from 'lodash' -import { FindOptions, Op, Order, ScopeOptions, Sequelize, Transaction } from 'sequelize' +import { FindOptions, Op, Order, ScopeOptions, Sequelize, Transaction, WhereOptions } from 'sequelize' import { AllowNull, BelongsTo, @@ -40,7 +40,7 @@ import { import { VideoCommentAbuseModel } from '../abuse/video-comment-abuse' import { AccountModel } from '../account/account' import { ActorModel, unusedActorAttributesForAPI } from '../activitypub/actor' -import { buildBlockedAccountSQL, buildLocalAccountIdsIn, getCommentSort, throwIfNotValid } from '../utils' +import { buildBlockedAccountSQL, buildBlockedAccountSQLOptimized, buildLocalAccountIdsIn, getCommentSort, throwIfNotValid } from '../utils' import { VideoModel } from './video' import { VideoChannelModel } from './video-channel' @@ -460,19 +460,20 @@ export class VideoCommentModel extends Model { const serverActor = await getServerActor() const { start, count, videoId, accountId, videoChannelId } = parameters - const accountExclusion = { - [Op.notIn]: Sequelize.literal( - '(' + buildBlockedAccountSQL([ serverActor.Account.id, '"Video->VideoChannel"."accountId"' ]) + ')' - ) + const whereAnd: WhereOptions[] = buildBlockedAccountSQLOptimized( + '"VideoCommentModel"."accountId"', + [ serverActor.Account.id, '"Video->VideoChannel"."accountId"' ] + ) + + if (accountId) { + whereAnd.push({ + [Op.eq]: accountId + }) + } + + const accountWhere = { + [Op.and]: whereAnd } - const accountWhere = accountId - ? { - [Op.and]: { - ...accountExclusion, - [Op.eq]: accountId - } - } - : accountExclusion const videoChannelWhere = videoChannelId ? { id: videoChannelId } : undefined