diff options
author | Chocobozzz <me@florianbigard.com> | 2022-04-15 15:07:20 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-04-15 15:07:20 +0200 |
commit | 2b0d17ccf46cfdba4103b7287f0dadf289ad4faf (patch) | |
tree | 3b006eff6a32126d8c260f99f561e2ac1901e4d1 /client/src/app/shared/shared-main | |
parent | d09ed46e71b78b4874de4afabefa2f9453c5894d (diff) | |
download | PeerTube-2b0d17ccf46cfdba4103b7287f0dadf289ad4faf.tar.gz PeerTube-2b0d17ccf46cfdba4103b7287f0dadf289ad4faf.tar.zst PeerTube-2b0d17ccf46cfdba4103b7287f0dadf289ad4faf.zip |
Reduce videos sort complexity
Automatically use best sort if user is logged in and chose hot algorithm
Diffstat (limited to 'client/src/app/shared/shared-main')
-rw-r--r-- | client/src/app/shared/shared-main/video/video.service.ts | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/client/src/app/shared/shared-main/video/video.service.ts b/client/src/app/shared/shared-main/video/video.service.ts index bc15c326f..142367506 100644 --- a/client/src/app/shared/shared-main/video/video.service.ts +++ b/client/src/app/shared/shared-main/video/video.service.ts | |||
@@ -3,7 +3,7 @@ import { from, Observable } from 'rxjs' | |||
3 | import { catchError, concatMap, map, switchMap, toArray } from 'rxjs/operators' | 3 | import { catchError, concatMap, map, switchMap, toArray } from 'rxjs/operators' |
4 | import { HttpClient, HttpParams, HttpRequest } from '@angular/common/http' | 4 | import { HttpClient, HttpParams, HttpRequest } from '@angular/common/http' |
5 | import { Injectable } from '@angular/core' | 5 | import { Injectable } from '@angular/core' |
6 | import { ComponentPaginationLight, RestExtractor, RestService, ServerService, UserService } from '@app/core' | 6 | import { AuthService, ComponentPaginationLight, RestExtractor, RestService, ServerService, UserService } from '@app/core' |
7 | import { objectToFormData } from '@app/helpers' | 7 | import { objectToFormData } from '@app/helpers' |
8 | import { | 8 | import { |
9 | BooleanBothQuery, | 9 | BooleanBothQuery, |
@@ -55,6 +55,7 @@ export class VideoService { | |||
55 | static BASE_SUBSCRIPTION_FEEDS_URL = environment.apiUrl + '/feeds/subscriptions.' | 55 | static BASE_SUBSCRIPTION_FEEDS_URL = environment.apiUrl + '/feeds/subscriptions.' |
56 | 56 | ||
57 | constructor ( | 57 | constructor ( |
58 | private auth: AuthService, | ||
58 | private authHttp: HttpClient, | 59 | private authHttp: HttpClient, |
59 | private restExtractor: RestExtractor, | 60 | private restExtractor: RestExtractor, |
60 | private restService: RestService, | 61 | private restService: RestService, |
@@ -418,7 +419,7 @@ export class VideoService { | |||
418 | ? this.restService.componentToRestPagination(videoPagination) | 419 | ? this.restService.componentToRestPagination(videoPagination) |
419 | : undefined | 420 | : undefined |
420 | 421 | ||
421 | let newParams = this.restService.addRestGetParams(params, pagination, sort) | 422 | let newParams = this.restService.addRestGetParams(params, pagination, this.buildListSort(sort)) |
422 | 423 | ||
423 | if (skipCount) newParams = newParams.set('skipCount', skipCount + '') | 424 | if (skipCount) newParams = newParams.set('skipCount', skipCount + '') |
424 | 425 | ||
@@ -434,6 +435,22 @@ export class VideoService { | |||
434 | return newParams | 435 | return newParams |
435 | } | 436 | } |
436 | 437 | ||
438 | private buildListSort (sortArg: VideoSortField | SortMeta) { | ||
439 | const sort = this.restService.buildSortString(sortArg) | ||
440 | |||
441 | if (typeof sort === 'string') { | ||
442 | // Silently use the best algorithm for logged in users if they chose the hot algorithm | ||
443 | if ( | ||
444 | this.auth.isLoggedIn() && | ||
445 | (sort === 'hot' || sort === '-hot') | ||
446 | ) { | ||
447 | return sort.replace('hot', 'best') | ||
448 | } | ||
449 | |||
450 | return sort | ||
451 | } | ||
452 | } | ||
453 | |||
437 | private setVideoRate (id: number, rateType: UserVideoRateType) { | 454 | private setVideoRate (id: number, rateType: UserVideoRateType) { |
438 | const url = `${VideoService.BASE_VIDEO_URL}/${id}/rate` | 455 | const url = `${VideoService.BASE_VIDEO_URL}/${id}/rate` |
439 | const body: UserVideoRateUpdate = { | 456 | const body: UserVideoRateUpdate = { |