aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models
diff options
context:
space:
mode:
Diffstat (limited to 'server/models')
-rw-r--r--server/models/utils.ts25
-rw-r--r--server/models/video/video-comment.ts29
-rw-r--r--server/models/video/video-format-utils.ts5
-rw-r--r--server/models/video/video-playlist-element.ts21
4 files changed, 53 insertions, 27 deletions
diff --git a/server/models/utils.ts b/server/models/utils.ts
index d706d9ea8..6e5522346 100644
--- a/server/models/utils.ts
+++ b/server/models/utils.ts
@@ -129,6 +129,30 @@ function buildBlockedAccountSQL (blockerIds: number[]) {
129 'WHERE "serverBlocklist"."accountId" IN (' + blockerIdsString + ')' 129 'WHERE "serverBlocklist"."accountId" IN (' + blockerIdsString + ')'
130} 130}
131 131
132function buildBlockedAccountSQLOptimized (columnNameJoin: string, blockerIds: number[]) {
133 const blockerIdsString = blockerIds.join(', ')
134
135 return [
136 literal(
137 `NOT EXISTS (` +
138 ` SELECT 1 FROM "accountBlocklist" ` +
139 ` WHERE "targetAccountId" = ${columnNameJoin} ` +
140 ` AND "accountId" IN (${blockerIdsString})` +
141 `)`
142 ),
143
144 literal(
145 `NOT EXISTS (` +
146 ` SELECT 1 FROM "account" ` +
147 ` INNER JOIN "actor" ON account."actorId" = actor.id ` +
148 ` INNER JOIN "serverBlocklist" ON "actor"."serverId" = "serverBlocklist"."targetServerId" ` +
149 ` WHERE "account"."id" = ${columnNameJoin} ` +
150 ` AND "serverBlocklist"."accountId" IN (${blockerIdsString})` +
151 `)`
152 )
153 ]
154}
155
132function buildServerIdsFollowedBy (actorId: any) { 156function buildServerIdsFollowedBy (actorId: any) {
133 const actorIdNumber = parseInt(actorId + '', 10) 157 const actorIdNumber = parseInt(actorId + '', 10)
134 158
@@ -201,6 +225,7 @@ function searchAttribute (sourceField?: string, targetField?: string) {
201 225
202export { 226export {
203 buildBlockedAccountSQL, 227 buildBlockedAccountSQL,
228 buildBlockedAccountSQLOptimized,
204 buildLocalActorIdsIn, 229 buildLocalActorIdsIn,
205 SortType, 230 SortType,
206 buildLocalAccountIdsIn, 231 buildLocalAccountIdsIn,
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 @@
1import * as Bluebird from 'bluebird' 1import * as Bluebird from 'bluebird'
2import { uniq } from 'lodash' 2import { uniq } from 'lodash'
3import { FindOptions, Op, Order, ScopeOptions, Sequelize, Transaction } from 'sequelize' 3import { FindOptions, Op, Order, ScopeOptions, Sequelize, Transaction, WhereOptions } from 'sequelize'
4import { 4import {
5 AllowNull, 5 AllowNull,
6 BelongsTo, 6 BelongsTo,
@@ -40,7 +40,7 @@ import {
40import { VideoCommentAbuseModel } from '../abuse/video-comment-abuse' 40import { VideoCommentAbuseModel } from '../abuse/video-comment-abuse'
41import { AccountModel } from '../account/account' 41import { AccountModel } from '../account/account'
42import { ActorModel, unusedActorAttributesForAPI } from '../activitypub/actor' 42import { ActorModel, unusedActorAttributesForAPI } from '../activitypub/actor'
43import { buildBlockedAccountSQL, buildLocalAccountIdsIn, getCommentSort, throwIfNotValid } from '../utils' 43import { buildBlockedAccountSQL, buildBlockedAccountSQLOptimized, buildLocalAccountIdsIn, getCommentSort, throwIfNotValid } from '../utils'
44import { VideoModel } from './video' 44import { VideoModel } from './video'
45import { VideoChannelModel } from './video-channel' 45import { 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
diff --git a/server/models/video/video-format-utils.ts b/server/models/video/video-format-utils.ts
index 9b6509dfd..7a17c839f 100644
--- a/server/models/video/video-format-utils.ts
+++ b/server/models/video/video-format-utils.ts
@@ -78,7 +78,10 @@ function videoModelToFormattedJSON (video: MVideoFormattable, options?: VideoFor
78 78
79 userHistory: userHistory ? { 79 userHistory: userHistory ? {
80 currentTime: userHistory.currentTime 80 currentTime: userHistory.currentTime
81 } : undefined 81 } : undefined,
82
83 // Can be added by external plugins
84 pluginData: (video as any).pluginData
82 } 85 }
83 86
84 if (options) { 87 if (options) {
diff --git a/server/models/video/video-playlist-element.ts b/server/models/video/video-playlist-element.ts
index ba92e129a..d357766e9 100644
--- a/server/models/video/video-playlist-element.ts
+++ b/server/models/video/video-playlist-element.ts
@@ -44,10 +44,6 @@ import { MUserAccountId } from '@server/types/models'
44 fields: [ 'videoId' ] 44 fields: [ 'videoId' ]
45 }, 45 },
46 { 46 {
47 fields: [ 'videoPlaylistId', 'videoId' ],
48 unique: true
49 },
50 {
51 fields: [ 'url' ], 47 fields: [ 'url' ],
52 unique: true 48 unique: true
53 } 49 }
@@ -60,8 +56,8 @@ export class VideoPlaylistElementModel extends Model<VideoPlaylistElementModel>
60 @UpdatedAt 56 @UpdatedAt
61 updatedAt: Date 57 updatedAt: Date
62 58
63 @AllowNull(false) 59 @AllowNull(true)
64 @Is('VideoPlaylistUrl', value => throwIfNotValid(value, isActivityPubUrlValid, 'url')) 60 @Is('VideoPlaylistUrl', value => throwIfNotValid(value, isActivityPubUrlValid, 'url', true))
65 @Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEO_PLAYLISTS.URL.max)) 61 @Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEO_PLAYLISTS.URL.max))
66 url: string 62 url: string
67 63
@@ -185,12 +181,11 @@ export class VideoPlaylistElementModel extends Model<VideoPlaylistElementModel>
185 return VideoPlaylistElementModel.findByPk(playlistElementId) 181 return VideoPlaylistElementModel.findByPk(playlistElementId)
186 } 182 }
187 183
188 static loadByPlaylistAndVideoForAP ( 184 static loadByPlaylistAndElementIdForAP (
189 playlistId: number | string, 185 playlistId: number | string,
190 videoId: number | string 186 playlistElementId: number
191 ): Bluebird<MVideoPlaylistElementVideoUrlPlaylistPrivacy> { 187 ): Bluebird<MVideoPlaylistElementVideoUrlPlaylistPrivacy> {
192 const playlistWhere = validator.isUUID('' + playlistId) ? { uuid: playlistId } : { id: playlistId } 188 const playlistWhere = validator.isUUID('' + playlistId) ? { uuid: playlistId } : { id: playlistId }
193 const videoWhere = validator.isUUID('' + videoId) ? { uuid: videoId } : { id: videoId }
194 189
195 const query = { 190 const query = {
196 include: [ 191 include: [
@@ -201,10 +196,12 @@ export class VideoPlaylistElementModel extends Model<VideoPlaylistElementModel>
201 }, 196 },
202 { 197 {
203 attributes: [ 'url' ], 198 attributes: [ 'url' ],
204 model: VideoModel.unscoped(), 199 model: VideoModel.unscoped()
205 where: videoWhere
206 } 200 }
207 ] 201 ],
202 where: {
203 id: playlistElementId
204 }
208 } 205 }
209 206
210 return VideoPlaylistElementModel.findOne(query) 207 return VideoPlaylistElementModel.findOne(query)