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-user-subscription | |
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-user-subscription')
-rw-r--r-- | client/src/app/shared/shared-user-subscription/user-subscription.service.ts | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/client/src/app/shared/shared-user-subscription/user-subscription.service.ts b/client/src/app/shared/shared-user-subscription/user-subscription.service.ts index eb1fdf91c..bb44660d2 100644 --- a/client/src/app/shared/shared-user-subscription/user-subscription.service.ts +++ b/client/src/app/shared/shared-user-subscription/user-subscription.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, switchMap, tap } from 'rxjs/operators' |
4 | import { bufferTime, catchError, filter, map, observeOn, share, switchMap, tap } 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 { ComponentPaginationLight, RestExtractor, RestService } from '@app/core' | 6 | import { ComponentPaginationLight, RestExtractor, RestService } from '@app/core' |
8 | import { enterZone, leaveZone } from '@app/helpers' | 7 | import { buildBulkObservable } from '@app/helpers' |
9 | import { Video, VideoChannel, VideoChannelService, VideoService } from '@app/shared/shared-main' | 8 | import { Video, VideoChannel, VideoChannelService, VideoService } from '@app/shared/shared-main' |
10 | import { ResultList, VideoChannel as VideoChannelServer, VideoSortField } from '@shared/models' | 9 | import { ResultList, VideoChannel as VideoChannelServer, VideoSortField } from '@shared/models' |
11 | import { environment } from '../../../environments/environment' | 10 | import { environment } from '../../../environments/environment' |
@@ -35,15 +34,12 @@ export class UserSubscriptionService { | |||
35 | private ngZone: NgZone | 34 | private ngZone: NgZone |
36 | ) { | 35 | ) { |
37 | this.existsObservable = merge( | 36 | this.existsObservable = merge( |
38 | this.existsSubject.pipe( | 37 | buildBulkObservable({ |
39 | // We leave Angular zone so Protractor does not get stuck | 38 | time: 500, |
40 | bufferTime(500, leaveZone(this.ngZone, asyncScheduler)), | 39 | ngZone: this.ngZone, |
41 | filter(uris => uris.length !== 0), | 40 | notifierObservable: this.existsSubject, |
42 | map(uris => uniq(uris)), | 41 | bulkGet: this.doSubscriptionsExist.bind(this) |
43 | observeOn(enterZone(this.ngZone, asyncScheduler)), | 42 | }), |
44 | switchMap(uris => this.doSubscriptionsExist(uris)), | ||
45 | share() | ||
46 | ), | ||
47 | 43 | ||
48 | this.myAccountSubscriptionCacheSubject | 44 | this.myAccountSubscriptionCacheSubject |
49 | ) | 45 | ) |