diff options
Diffstat (limited to 'server/models/video/video-comment.ts')
-rw-r--r-- | server/models/video/video-comment.ts | 29 |
1 files changed, 15 insertions, 14 deletions
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 @@ | |||
1 | import * as Bluebird from 'bluebird' | 1 | import * as Bluebird from 'bluebird' |
2 | import { uniq } from 'lodash' | 2 | import { uniq } from 'lodash' |
3 | import { FindOptions, Op, Order, ScopeOptions, Sequelize, Transaction } from 'sequelize' | 3 | import { FindOptions, Op, Order, ScopeOptions, Sequelize, Transaction, WhereOptions } from 'sequelize' |
4 | import { | 4 | import { |
5 | AllowNull, | 5 | AllowNull, |
6 | BelongsTo, | 6 | BelongsTo, |
@@ -40,7 +40,7 @@ import { | |||
40 | import { VideoCommentAbuseModel } from '../abuse/video-comment-abuse' | 40 | import { VideoCommentAbuseModel } from '../abuse/video-comment-abuse' |
41 | import { AccountModel } from '../account/account' | 41 | import { AccountModel } from '../account/account' |
42 | import { ActorModel, unusedActorAttributesForAPI } from '../activitypub/actor' | 42 | import { ActorModel, unusedActorAttributesForAPI } from '../activitypub/actor' |
43 | import { buildBlockedAccountSQL, buildLocalAccountIdsIn, getCommentSort, throwIfNotValid } from '../utils' | 43 | import { buildBlockedAccountSQL, buildBlockedAccountSQLOptimized, buildLocalAccountIdsIn, getCommentSort, throwIfNotValid } from '../utils' |
44 | import { VideoModel } from './video' | 44 | import { VideoModel } from './video' |
45 | import { VideoChannelModel } from './video-channel' | 45 | import { VideoChannelModel } from './video-channel' |
46 | 46 | ||
@@ -460,19 +460,20 @@ export class VideoCommentModel extends Model<VideoCommentModel> { | |||
460 | const serverActor = await getServerActor() | 460 | const serverActor = await getServerActor() |
461 | const { start, count, videoId, accountId, videoChannelId } = parameters | 461 | const { start, count, videoId, accountId, videoChannelId } = parameters |
462 | 462 | ||
463 | const accountExclusion = { | 463 | const whereAnd: WhereOptions[] = buildBlockedAccountSQLOptimized( |
464 | [Op.notIn]: Sequelize.literal( | 464 | '"VideoCommentModel"."accountId"', |
465 | '(' + buildBlockedAccountSQL([ serverActor.Account.id, '"Video->VideoChannel"."accountId"' ]) + ')' | 465 | [ serverActor.Account.id, '"Video->VideoChannel"."accountId"' ] |
466 | ) | 466 | ) |
467 | |||
468 | if (accountId) { | ||
469 | whereAnd.push({ | ||
470 | [Op.eq]: accountId | ||
471 | }) | ||
472 | } | ||
473 | |||
474 | const accountWhere = { | ||
475 | [Op.and]: whereAnd | ||
467 | } | 476 | } |
468 | const accountWhere = accountId | ||
469 | ? { | ||
470 | [Op.and]: { | ||
471 | ...accountExclusion, | ||
472 | [Op.eq]: accountId | ||
473 | } | ||
474 | } | ||
475 | : accountExclusion | ||
476 | 477 | ||
477 | const videoChannelWhere = videoChannelId ? { id: videoChannelId } : undefined | 478 | const videoChannelWhere = videoChannelId ? { id: videoChannelId } : undefined |
478 | 479 | ||