aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/video.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-08-30 14:58:00 +0200
committerChocobozzz <me@florianbigard.com>2018-08-31 09:19:58 +0200
commit2d3741d6d92e9bd1f41694c7442a6d1da434e1f2 (patch)
tree93a1e609e14bc14ca9e77a6661ddc9c0e461d6f3 /server/models/video/video.ts
parentd9eaee3939bf2e93e5d775d32bce77842201faba (diff)
downloadPeerTube-2d3741d6d92e9bd1f41694c7442a6d1da434e1f2.tar.gz
PeerTube-2d3741d6d92e9bd1f41694c7442a6d1da434e1f2.tar.zst
PeerTube-2d3741d6d92e9bd1f41694c7442a6d1da434e1f2.zip
Videos overview page: first version
Diffstat (limited to 'server/models/video/video.ts')
-rw-r--r--server/models/video/video.ts23
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 {