]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/video/video-query-builder.ts
Update data in DB when regenerate thumbnails
[github/Chocobozzz/PeerTube.git] / server / models / video / video-query-builder.ts
index af1878e7a286272d4196a5f4ceacab6d5a674e04..4d95ddee29a8b1fcaf5f7a561baae499c73e8a5c 100644 (file)
@@ -266,13 +266,14 @@ function buildListQuery (model: typeof Model, options: BuildVideosQueryOptions)
        *  - weights and base score are in number of half-days.
        *  - all comments are counted, regardless of being written by the video author or not
        * see https://github.com/reddit-archive/reddit/blob/master/r2/r2/lib/db/_sorts.pyx#L47-L58
+       *  - we have less interactions than on reddit, so multiply weights by an arbitrary factor
        */
       const weights = {
-        like: 3,
-        dislike: -3,
-        view: 1 / 12,
-        comment: 2, // a comment takes more time than a like to do, but can be done multiple times
-        history: -2
+        like: 3 * 50,
+        dislike: -3 * 50,
+        view: Math.floor((1 / 3) * 50),
+        comment: 2 * 50, // a comment takes more time than a like to do, but can be done multiple times
+        history: -2 * 50
       }
 
       joins.push('LEFT JOIN "videoComment" ON "video"."id" = "videoComment"."videoId"')
@@ -282,7 +283,7 @@ function buildListQuery (model: typeof Model, options: BuildVideosQueryOptions)
         `+ LOG(GREATEST(1, "video"."dislikes" - 1)) * ${weights.dislike} ` + // dislikes (-)
         `+ LOG("video"."views" + 1) * ${weights.view} ` + // views (+)
         `+ LOG(GREATEST(1, COUNT(DISTINCT "videoComment"."id"))) * ${weights.comment} ` + // comments (+)
-        '+ (SELECT EXTRACT(epoch FROM "video"."publishedAt") / 47000) ' // base score (in number of half-days)
+        '+ (SELECT (EXTRACT(epoch FROM "video"."publishedAt") - 1446156582) / 47000) ' // base score (in number of half-days)
 
       if (options.trendingAlgorithm === 'best' && options.user) {
         joins.push(
@@ -489,12 +490,13 @@ function wrapForAPIResults (baseQuery: string, replacements: any, options: Build
     'INNER JOIN "actor" AS "VideoChannel->Account->Actor" ON "VideoChannel->Account"."actorId" = "VideoChannel->Account->Actor"."id"',
 
     'LEFT OUTER JOIN "server" AS "VideoChannel->Actor->Server" ON "VideoChannel->Actor"."serverId" = "VideoChannel->Actor->Server"."id"',
-    'LEFT OUTER JOIN "avatar" AS "VideoChannel->Actor->Avatar" ON "VideoChannel->Actor"."avatarId" = "VideoChannel->Actor->Avatar"."id"',
+    'LEFT OUTER JOIN "actorImage" AS "VideoChannel->Actor->Avatar" ' +
+      'ON "VideoChannel->Actor"."avatarId" = "VideoChannel->Actor->Avatar"."id"',
 
     'LEFT OUTER JOIN "server" AS "VideoChannel->Account->Actor->Server" ' +
       'ON "VideoChannel->Account->Actor"."serverId" = "VideoChannel->Account->Actor->Server"."id"',
 
-    'LEFT OUTER JOIN "avatar" AS "VideoChannel->Account->Actor->Avatar" ' +
+    'LEFT OUTER JOIN "actorImage" AS "VideoChannel->Account->Actor->Avatar" ' +
       'ON "VideoChannel->Account->Actor"."avatarId" = "VideoChannel->Account->Actor->Avatar"."id"',
 
     'LEFT OUTER JOIN "thumbnail" AS "Thumbnails" ON "video"."id" = "Thumbnails"."videoId"'