diff options
Diffstat (limited to 'server/models/video/video.ts')
-rw-r--r-- | server/models/video/video.ts | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 3410833c8..695990b17 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts | |||
@@ -1083,6 +1083,29 @@ export class VideoModel extends Model<VideoModel> { | |||
1083 | }) | 1083 | }) |
1084 | } | 1084 | } |
1085 | 1085 | ||
1086 | // threshold corresponds to how many video the field should have to be returned | ||
1087 | static getRandomFieldSamples (field: 'category' | 'channelId', threshold: number, count: number) { | ||
1088 | const query: IFindOptions<VideoModel> = { | ||
1089 | attributes: [ field ], | ||
1090 | limit: count, | ||
1091 | group: field, | ||
1092 | having: Sequelize.where(Sequelize.fn('COUNT', Sequelize.col(field)), { | ||
1093 | [Sequelize.Op.gte]: threshold | ||
1094 | }) as any, // FIXME: typings | ||
1095 | where: { | ||
1096 | [field]: { | ||
1097 | [Sequelize.Op.not]: null, | ||
1098 | }, | ||
1099 | privacy: VideoPrivacy.PUBLIC, | ||
1100 | state: VideoState.PUBLISHED | ||
1101 | }, | ||
1102 | order: [ this.sequelize.random() ] | ||
1103 | } | ||
1104 | |||
1105 | return VideoModel.findAll(query) | ||
1106 | .then(rows => rows.map(r => r[field])) | ||
1107 | } | ||
1108 | |||
1086 | private static buildActorWhereWithFilter (filter?: VideoFilter) { | 1109 | private static buildActorWhereWithFilter (filter?: VideoFilter) { |
1087 | if (filter && filter === 'local') { | 1110 | if (filter && filter === 'local') { |
1088 | return { | 1111 | return { |