aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/video.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-09-14 09:57:21 +0200
committerChocobozzz <me@florianbigard.com>2018-09-14 09:57:21 +0200
commitb36f41ca09e92ecb30d367d91d1089a23d10d585 (patch)
tree34b7c90e17f73f37d069a2f08d60dc36fa08372f /server/models/video/video.ts
parent6f0c46be8c9f4690d5e5cb758c4df6164b006f83 (diff)
downloadPeerTube-b36f41ca09e92ecb30d367d91d1089a23d10d585.tar.gz
PeerTube-b36f41ca09e92ecb30d367d91d1089a23d10d585.tar.zst
PeerTube-b36f41ca09e92ecb30d367d91d1089a23d10d585.zip
Add trending videos strategy
Diffstat (limited to 'server/models/video/video.ts')
-rw-r--r--server/models/video/video.ts32
1 files changed, 20 insertions, 12 deletions
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index 27c631dcd..ef8be7c86 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -387,16 +387,7 @@ type AvailableForListIDsOptions = {
387 } 387 }
388 388
389 if (options.trendingDays) { 389 if (options.trendingDays) {
390 query.include.push({ 390 query.include.push(VideoModel.buildTrendingQuery(options.trendingDays))
391 attributes: [],
392 model: VideoViewModel,
393 required: false,
394 where: {
395 startDate: {
396 [ Sequelize.Op.gte ]: new Date(new Date().getTime() - (24 * 3600 * 1000) * options.trendingDays)
397 }
398 }
399 })
400 391
401 query.subQuery = false 392 query.subQuery = false
402 } 393 }
@@ -1071,9 +1062,12 @@ export class VideoModel extends Model<VideoModel> {
1071 } 1062 }
1072 1063
1073 static load (id: number, t?: Sequelize.Transaction) { 1064 static load (id: number, t?: Sequelize.Transaction) {
1074 const options = t ? { transaction: t } : undefined 1065 return VideoModel.findById(id, { transaction: t })
1066 }
1075 1067
1076 return VideoModel.findById(id, options) 1068 static loadWithFile (id: number, t?: Sequelize.Transaction, logging?: boolean) {
1069 return VideoModel.scope(ScopeNames.WITH_FILES)
1070 .findById(id, { transaction: t, logging })
1077 } 1071 }
1078 1072
1079 static loadByUrlAndPopulateAccount (url: string, t?: Sequelize.Transaction) { 1073 static loadByUrlAndPopulateAccount (url: string, t?: Sequelize.Transaction) {
@@ -1191,6 +1185,20 @@ export class VideoModel extends Model<VideoModel> {
1191 .then(rows => rows.map(r => r[ field ])) 1185 .then(rows => rows.map(r => r[ field ]))
1192 } 1186 }
1193 1187
1188 static buildTrendingQuery (trendingDays: number) {
1189 return {
1190 attributes: [],
1191 subQuery: false,
1192 model: VideoViewModel,
1193 required: false,
1194 where: {
1195 startDate: {
1196 [ Sequelize.Op.gte ]: new Date(new Date().getTime() - (24 * 3600 * 1000) * trendingDays)
1197 }
1198 }
1199 }
1200 }
1201
1194 private static buildActorWhereWithFilter (filter?: VideoFilter) { 1202 private static buildActorWhereWithFilter (filter?: VideoFilter) {
1195 if (filter && filter === 'local') { 1203 if (filter && filter === 'local') {
1196 return { 1204 return {