diff options
author | Chocobozzz <me@florianbigard.com> | 2021-08-02 15:29:09 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-08-02 15:40:09 +0200 |
commit | 3da38d6e9f8d600476be276666ac7223aa5f172c (patch) | |
tree | daec25cccb900a0f90fc9d2273099683b42d8551 /client/src/app/shared/shared-video-playlist | |
parent | 200eaf5152ca72fe6b05a49caf819e22bd045b37 (diff) | |
download | PeerTube-3da38d6e9f8d600476be276666ac7223aa5f172c.tar.gz PeerTube-3da38d6e9f8d600476be276666ac7223aa5f172c.tar.zst PeerTube-3da38d6e9f8d600476be276666ac7223aa5f172c.zip |
Fetch things in bulk for the homepage
Diffstat (limited to 'client/src/app/shared/shared-video-playlist')
-rw-r--r-- | client/src/app/shared/shared-video-playlist/video-playlist.service.ts | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/client/src/app/shared/shared-video-playlist/video-playlist.service.ts b/client/src/app/shared/shared-video-playlist/video-playlist.service.ts index 1b87e0b2a..a3f1393ff 100644 --- a/client/src/app/shared/shared-video-playlist/video-playlist.service.ts +++ b/client/src/app/shared/shared-video-playlist/video-playlist.service.ts | |||
@@ -1,11 +1,10 @@ | |||
1 | import * as debug from 'debug' | 1 | import * as debug from 'debug' |
2 | import { uniq } from 'lodash-es' | 2 | import { merge, Observable, of, ReplaySubject, Subject } from 'rxjs' |
3 | import { asyncScheduler, merge, Observable, of, ReplaySubject, Subject } from 'rxjs' | 3 | import { catchError, filter, map, share, switchMap, tap } from 'rxjs/operators' |
4 | import { bufferTime, catchError, filter, map, observeOn, share, switchMap, tap, distinctUntilChanged } from 'rxjs/operators' | ||
5 | import { HttpClient, HttpParams } from '@angular/common/http' | 4 | import { HttpClient, HttpParams } from '@angular/common/http' |
6 | import { Injectable, NgZone } from '@angular/core' | 5 | import { Injectable, NgZone } from '@angular/core' |
7 | import { AuthUser, ComponentPaginationLight, RestExtractor, RestService, ServerService } from '@app/core' | 6 | import { AuthUser, ComponentPaginationLight, RestExtractor, RestService, ServerService } from '@app/core' |
8 | import { enterZone, leaveZone, objectToFormData } from '@app/helpers' | 7 | import { buildBulkObservable, objectToFormData } from '@app/helpers' |
9 | import { Account, AccountService, VideoChannel, VideoChannelService } from '@app/shared/shared-main' | 8 | import { Account, AccountService, VideoChannel, VideoChannelService } from '@app/shared/shared-main' |
10 | import { | 9 | import { |
11 | ResultList, | 10 | ResultList, |
@@ -52,16 +51,12 @@ export class VideoPlaylistService { | |||
52 | private ngZone: NgZone | 51 | private ngZone: NgZone |
53 | ) { | 52 | ) { |
54 | this.videoExistsInPlaylistObservable = merge( | 53 | this.videoExistsInPlaylistObservable = merge( |
55 | this.videoExistsInPlaylistNotifier.pipe( | 54 | buildBulkObservable({ |
56 | distinctUntilChanged(), | 55 | time: 500, |
57 | // We leave Angular zone so Protractor does not get stuck | 56 | ngZone: this.ngZone, |
58 | bufferTime(500, leaveZone(this.ngZone, asyncScheduler)), | 57 | bulkGet: this.doVideosExistInPlaylist.bind(this), |
59 | filter(videoIds => videoIds.length !== 0), | 58 | notifierObservable: this.videoExistsInPlaylistNotifier |
60 | map(videoIds => uniq(videoIds)), | 59 | }), |
61 | observeOn(enterZone(this.ngZone, asyncScheduler)), | ||
62 | switchMap(videoIds => this.doVideosExistInPlaylist(videoIds)), | ||
63 | share() | ||
64 | ), | ||
65 | 60 | ||
66 | this.videoExistsInPlaylistCacheSubject | 61 | this.videoExistsInPlaylistCacheSubject |
67 | ) | 62 | ) |