From 010382b6037cff5d0ed16fa8b158691439fac9b7 Mon Sep 17 00:00:00 2001
From: Chocobozzz <me@florianbigard.com>
Date: Fri, 3 Jun 2022 14:04:52 +0200
Subject: [PATCH] Completely remove best default trending algorithm

---
 CHANGELOG.md                                                  | 1 +
 .../+videos/video-list/videos-list-common-page.component.ts   | 4 ++++
 config/default.yaml                                           | 1 -
 config/production.yaml.example                                | 1 -
 server/tests/api/check-params/config.ts                       | 2 +-
 server/tests/api/server/config.ts                             | 2 +-
 shared/server-commands/server/config-command.ts               | 2 +-
 7 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index f3724a3bf..8aeeb7b7e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,6 +16,7 @@
  * Add `client.videos.resumable_upload.max_chunk_size` config option [#4857](https://github.com/Chocobozzz/PeerTube/pull/4857)
  * Add `object_storage.upload_acl` config option [#4861](https://github.com/Chocobozzz/PeerTube/pull/4861)
  * Add ability to set RTMP/RTMPS listening hostname using `rtmp.hostname`/`rtmps.hostname` and public RTMP/RTMPS hostname using `rtmp.public_hostname`/`rtmps.public_hostname`
+ * Removed `best` default trending algorithm. It is automatically used if using `hot` algorithm with a logged in user
 
 ### Docker
 
diff --git a/client/src/app/+videos/video-list/videos-list-common-page.component.ts b/client/src/app/+videos/video-list/videos-list-common-page.component.ts
index 72c7e1ef6..d2782036b 100644
--- a/client/src/app/+videos/video-list/videos-list-common-page.component.ts
+++ b/client/src/app/+videos/video-list/videos-list-common-page.component.ts
@@ -173,6 +173,10 @@ export class VideosListCommonPageComponent implements OnInit, OnDestroy, Disable
       case 'most-liked':
         return '-likes'
 
+      // We'll automatically apply "best" sort if using "hot" sort with a logged user
+      case 'best':
+        return '-hot'
+
       default:
         return '-' + algorithm as VideoSortField
     }
diff --git a/config/default.yaml b/config/default.yaml
index 689f81343..54452d5e2 100644
--- a/config/default.yaml
+++ b/config/default.yaml
@@ -181,7 +181,6 @@ trending:
     interval_days: 7 # Compute trending videos for the last x days
     algorithms:
       enabled:
-        - 'best' # adaptation of Reddit's 'Best' algorithm (Hot minus History)
         - 'hot' # adaptation of Reddit's 'Hot' algorithm
         - 'most-viewed' # default, used initially by PeerTube as the trending page
         - 'most-liked'
diff --git a/config/production.yaml.example b/config/production.yaml.example
index 6db43fccf..89b7fe966 100644
--- a/config/production.yaml.example
+++ b/config/production.yaml.example
@@ -177,7 +177,6 @@ trending:
     interval_days: 7 # Compute trending videos for the last x days
     algorithms:
       enabled:
-        - 'best' # adaptation of Reddit's 'Best' algorithm (Hot minus History)
         - 'hot' # adaptation of Reddit's 'Hot' algorithm
         - 'most-viewed' # default, used initially by PeerTube as the trending page
         - 'most-liked'
diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts
index c8dbbf797..99fb24a5b 100644
--- a/server/tests/api/check-params/config.ts
+++ b/server/tests/api/check-params/config.ts
@@ -165,7 +165,7 @@ describe('Test config API validators', function () {
     trending: {
       videos: {
         algorithms: {
-          enabled: [ 'best', 'hot', 'most-viewed', 'most-liked' ],
+          enabled: [ 'hot', 'most-viewed', 'most-liked' ],
           default: 'most-viewed'
         }
       }
diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts
index f31012a5c..0f2fb5493 100644
--- a/server/tests/api/server/config.ts
+++ b/server/tests/api/server/config.ts
@@ -367,7 +367,7 @@ const newCustomConfig: CustomConfig = {
   trending: {
     videos: {
       algorithms: {
-        enabled: [ 'best', 'hot', 'most-viewed', 'most-liked' ],
+        enabled: [ 'hot', 'most-viewed', 'most-liked' ],
         default: 'hot'
       }
     }
diff --git a/shared/server-commands/server/config-command.ts b/shared/server-commands/server/config-command.ts
index ed4961bc3..5320dead4 100644
--- a/shared/server-commands/server/config-command.ts
+++ b/shared/server-commands/server/config-command.ts
@@ -356,7 +356,7 @@ export class ConfigCommand extends AbstractCommand {
       trending: {
         videos: {
           algorithms: {
-            enabled: [ 'best', 'hot', 'most-viewed', 'most-liked' ],
+            enabled: [ 'hot', 'most-viewed', 'most-liked' ],
             default: 'hot'
           }
         }