]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/video/video-query-builder.ts
Translated using Weblate (French)
[github/Chocobozzz/PeerTube.git] / server / models / video / video-query-builder.ts
index 822d0c89bd7359e25c05856b7bd0bbf19d2f35db..96df0a7f81ea77519f2905c368c18413675a81e1 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(
@@ -516,6 +517,10 @@ function wrapForAPIResults (baseQuery: string, replacements: any, options: Build
       '"VideoFiles"."resolution"': '"VideoFiles.resolution"',
       '"VideoFiles"."size"': '"VideoFiles.size"',
       '"VideoFiles"."extname"': '"VideoFiles.extname"',
+      '"VideoFiles"."filename"': '"VideoFiles.filename"',
+      '"VideoFiles"."fileUrl"': '"VideoFiles.fileUrl"',
+      '"VideoFiles"."torrentFilename"': '"VideoFiles.torrentFilename"',
+      '"VideoFiles"."torrentUrl"': '"VideoFiles.torrentUrl"',
       '"VideoFiles"."infoHash"': '"VideoFiles.infoHash"',
       '"VideoFiles"."fps"': '"VideoFiles.fps"',
       '"VideoFiles"."videoId"': '"VideoFiles.videoId"',
@@ -529,6 +534,10 @@ function wrapForAPIResults (baseQuery: string, replacements: any, options: Build
       '"VideoStreamingPlaylists->VideoFiles"."resolution"': '"VideoStreamingPlaylists.VideoFiles.resolution"',
       '"VideoStreamingPlaylists->VideoFiles"."size"': '"VideoStreamingPlaylists.VideoFiles.size"',
       '"VideoStreamingPlaylists->VideoFiles"."extname"': '"VideoStreamingPlaylists.VideoFiles.extname"',
+      '"VideoStreamingPlaylists->VideoFiles"."filename"': '"VideoStreamingPlaylists.VideoFiles.filename"',
+      '"VideoStreamingPlaylists->VideoFiles"."fileUrl"': '"VideoStreamingPlaylists.VideoFiles.fileUrl"',
+      '"VideoStreamingPlaylists->VideoFiles"."torrentFilename"': '"VideoStreamingPlaylists.VideoFiles.torrentFilename"',
+      '"VideoStreamingPlaylists->VideoFiles"."torrentUrl"': '"VideoStreamingPlaylists.VideoFiles.torrentUrl"',
       '"VideoStreamingPlaylists->VideoFiles"."infoHash"': '"VideoStreamingPlaylists.VideoFiles.infoHash"',
       '"VideoStreamingPlaylists->VideoFiles"."fps"': '"VideoStreamingPlaylists.VideoFiles.fps"',
       '"VideoStreamingPlaylists->VideoFiles"."videoStreamingPlaylistId"': '"VideoStreamingPlaylists.VideoFiles.videoStreamingPlaylistId"',