aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/video-query-builder.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-03-03 13:52:58 +0100
committerChocobozzz <me@florianbigard.com>2021-03-03 13:52:58 +0100
commit5a22296bdb0e82e6318c46335248eee49fb90e11 (patch)
tree13645414c744e63798bac94c0c002362faf4599d /server/models/video/video-query-builder.ts
parent534556052ed4aab539325dccaa16c6dd2acecf73 (diff)
downloadPeerTube-5a22296bdb0e82e6318c46335248eee49fb90e11.tar.gz
PeerTube-5a22296bdb0e82e6318c46335248eee49fb90e11.tar.zst
PeerTube-5a22296bdb0e82e6318c46335248eee49fb90e11.zip
Fix broken hot algorithm
Diffstat (limited to 'server/models/video/video-query-builder.ts')
-rw-r--r--server/models/video/video-query-builder.ts13
1 files changed, 7 insertions, 6 deletions
diff --git a/server/models/video/video-query-builder.ts b/server/models/video/video-query-builder.ts
index af1878e7a..96df0a7f8 100644
--- a/server/models/video/video-query-builder.ts
+++ b/server/models/video/video-query-builder.ts
@@ -266,13 +266,14 @@ function buildListQuery (model: typeof Model, options: BuildVideosQueryOptions)
266 * - weights and base score are in number of half-days. 266 * - weights and base score are in number of half-days.
267 * - all comments are counted, regardless of being written by the video author or not 267 * - all comments are counted, regardless of being written by the video author or not
268 * see https://github.com/reddit-archive/reddit/blob/master/r2/r2/lib/db/_sorts.pyx#L47-L58 268 * see https://github.com/reddit-archive/reddit/blob/master/r2/r2/lib/db/_sorts.pyx#L47-L58
269 * - we have less interactions than on reddit, so multiply weights by an arbitrary factor
269 */ 270 */
270 const weights = { 271 const weights = {
271 like: 3, 272 like: 3 * 50,
272 dislike: -3, 273 dislike: -3 * 50,
273 view: 1 / 12, 274 view: Math.floor((1 / 3) * 50),
274 comment: 2, // a comment takes more time than a like to do, but can be done multiple times 275 comment: 2 * 50, // a comment takes more time than a like to do, but can be done multiple times
275 history: -2 276 history: -2 * 50
276 } 277 }
277 278
278 joins.push('LEFT JOIN "videoComment" ON "video"."id" = "videoComment"."videoId"') 279 joins.push('LEFT JOIN "videoComment" ON "video"."id" = "videoComment"."videoId"')
@@ -282,7 +283,7 @@ function buildListQuery (model: typeof Model, options: BuildVideosQueryOptions)
282 `+ LOG(GREATEST(1, "video"."dislikes" - 1)) * ${weights.dislike} ` + // dislikes (-) 283 `+ LOG(GREATEST(1, "video"."dislikes" - 1)) * ${weights.dislike} ` + // dislikes (-)
283 `+ LOG("video"."views" + 1) * ${weights.view} ` + // views (+) 284 `+ LOG("video"."views" + 1) * ${weights.view} ` + // views (+)
284 `+ LOG(GREATEST(1, COUNT(DISTINCT "videoComment"."id"))) * ${weights.comment} ` + // comments (+) 285 `+ LOG(GREATEST(1, COUNT(DISTINCT "videoComment"."id"))) * ${weights.comment} ` + // comments (+)
285 '+ (SELECT EXTRACT(epoch FROM "video"."publishedAt") / 47000) ' // base score (in number of half-days) 286 '+ (SELECT (EXTRACT(epoch FROM "video"."publishedAt") - 1446156582) / 47000) ' // base score (in number of half-days)
286 287
287 if (options.trendingAlgorithm === 'best' && options.user) { 288 if (options.trendingAlgorithm === 'best' && options.user) {
288 joins.push( 289 joins.push(