aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/video.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/video/video.ts')
-rw-r--r--server/models/video/video.ts27
1 files changed, 14 insertions, 13 deletions
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index 23d1dedd6..b7d3f184f 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -929,7 +929,7 @@ export class VideoModel extends Model<VideoModel> {
929 videoChannelId?: number, 929 videoChannelId?: number,
930 actorId?: number 930 actorId?: number
931 trendingDays?: number 931 trendingDays?: number
932 }) { 932 }, countVideos = true) {
933 const query: IFindOptions<VideoModel> = { 933 const query: IFindOptions<VideoModel> = {
934 offset: options.start, 934 offset: options.start,
935 limit: options.count, 935 limit: options.count,
@@ -962,7 +962,7 @@ export class VideoModel extends Model<VideoModel> {
962 trendingDays 962 trendingDays
963 } 963 }
964 964
965 return VideoModel.getAvailableForApi(query, queryOptions) 965 return VideoModel.getAvailableForApi(query, queryOptions, countVideos)
966 } 966 }
967 967
968 static async searchAndPopulateAccountAndServer (options: { 968 static async searchAndPopulateAccountAndServer (options: {
@@ -1164,7 +1164,14 @@ export class VideoModel extends Model<VideoModel> {
1164 } 1164 }
1165 1165
1166 // threshold corresponds to how many video the field should have to be returned 1166 // threshold corresponds to how many video the field should have to be returned
1167 static getRandomFieldSamples (field: 'category' | 'channelId', threshold: number, count: number) { 1167 static async getRandomFieldSamples (field: 'category' | 'channelId', threshold: number, count: number) {
1168 const actorId = (await getServerActor()).id
1169
1170 const scopeOptions = {
1171 actorId,
1172 includeLocalVideos: true
1173 }
1174
1168 const query: IFindOptions<VideoModel> = { 1175 const query: IFindOptions<VideoModel> = {
1169 attributes: [ field ], 1176 attributes: [ field ],
1170 limit: count, 1177 limit: count,
@@ -1172,17 +1179,11 @@ export class VideoModel extends Model<VideoModel> {
1172 having: Sequelize.where(Sequelize.fn('COUNT', Sequelize.col(field)), { 1179 having: Sequelize.where(Sequelize.fn('COUNT', Sequelize.col(field)), {
1173 [ Sequelize.Op.gte ]: threshold 1180 [ Sequelize.Op.gte ]: threshold
1174 }) as any, // FIXME: typings 1181 }) as any, // FIXME: typings
1175 where: {
1176 [ field ]: {
1177 [ Sequelize.Op.not ]: null
1178 },
1179 privacy: VideoPrivacy.PUBLIC,
1180 state: VideoState.PUBLISHED
1181 },
1182 order: [ this.sequelize.random() ] 1182 order: [ this.sequelize.random() ]
1183 } 1183 }
1184 1184
1185 return VideoModel.findAll(query) 1185 return VideoModel.scope({ method: [ ScopeNames.AVAILABLE_FOR_LIST_IDS, scopeOptions ] })
1186 .findAll(query)
1186 .then(rows => rows.map(r => r[ field ])) 1187 .then(rows => rows.map(r => r[ field ]))
1187 } 1188 }
1188 1189
@@ -1210,7 +1211,7 @@ export class VideoModel extends Model<VideoModel> {
1210 return {} 1211 return {}
1211 } 1212 }
1212 1213
1213 private static async getAvailableForApi (query: IFindOptions<VideoModel>, options: AvailableForListIDsOptions) { 1214 private static async getAvailableForApi (query: IFindOptions<VideoModel>, options: AvailableForListIDsOptions, countVideos = true) {
1214 const idsScope = { 1215 const idsScope = {
1215 method: [ 1216 method: [
1216 ScopeNames.AVAILABLE_FOR_LIST_IDS, options 1217 ScopeNames.AVAILABLE_FOR_LIST_IDS, options
@@ -1227,7 +1228,7 @@ export class VideoModel extends Model<VideoModel> {
1227 } 1228 }
1228 1229
1229 const [ count, rowsId ] = await Promise.all([ 1230 const [ count, rowsId ] = await Promise.all([
1230 VideoModel.scope(countScope).count(countQuery), 1231 countVideos ? VideoModel.scope(countScope).count(countQuery) : Promise.resolve(undefined),
1231 VideoModel.scope(idsScope).findAll(query) 1232 VideoModel.scope(idsScope).findAll(query)
1232 ]) 1233 ])
1233 const ids = rowsId.map(r => r.id) 1234 const ids = rowsId.map(r => r.id)