aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-10-18 11:44:54 +0200
committerChocobozzz <me@florianbigard.com>2021-10-18 11:44:54 +0200
commit2cc276f92fefeff88fcc74217e1174a3ddb3f074 (patch)
tree1f87381575de9500d96739cf85321e3e5edb0bf7
parent27c3c9456dcf436946635c3c85d4a7653b5cccdb (diff)
downloadPeerTube-2cc276f92fefeff88fcc74217e1174a3ddb3f074.tar.gz
PeerTube-2cc276f92fefeff88fcc74217e1174a3ddb3f074.tar.zst
PeerTube-2cc276f92fefeff88fcc74217e1174a3ddb3f074.zip
Fix find in bulk
-rw-r--r--client/src/app/helpers/rxjs.ts11
-rw-r--r--client/src/app/shared/shared-search/find-in-bulk.service.ts11
-rw-r--r--client/src/app/shared/shared-user-subscription/user-subscription.service.ts2
-rw-r--r--client/src/app/shared/shared-video-playlist/video-playlist.service.ts2
4 files changed, 15 insertions, 11 deletions
diff --git a/client/src/app/helpers/rxjs.ts b/client/src/app/helpers/rxjs.ts
index 625bca0f7..2eaf0a055 100644
--- a/client/src/app/helpers/rxjs.ts
+++ b/client/src/app/helpers/rxjs.ts
@@ -2,10 +2,10 @@ import { uniq } from 'lodash-es'
2import { Observable } from 'rxjs' 2import { Observable } from 'rxjs'
3import { bufferTime, distinctUntilChanged, filter, map, share, switchMap } from 'rxjs/operators' 3import { bufferTime, distinctUntilChanged, filter, map, share, switchMap } from 'rxjs/operators'
4 4
5function buildBulkObservable <T extends number | string, R> (options: { 5function buildBulkObservable <P extends number | string, R> (options: {
6 notifierObservable: Observable<T> 6 notifierObservable: Observable<P>
7 time: number 7 time: number
8 bulkGet: (params: T[]) => Observable<R> 8 bulkGet: (params: P[]) => Observable<R>
9}) { 9}) {
10 const { notifierObservable, time, bulkGet } = options 10 const { notifierObservable, time, bulkGet } = options
11 11
@@ -14,7 +14,10 @@ function buildBulkObservable <T extends number | string, R> (options: {
14 bufferTime(time), 14 bufferTime(time),
15 filter(params => params.length !== 0), 15 filter(params => params.length !== 0),
16 map(params => uniq(params)), 16 map(params => uniq(params)),
17 switchMap(params => bulkGet(params)), 17 switchMap(params => {
18 return bulkGet(params)
19 .pipe(map(response => ({ params, response })))
20 }),
18 share() 21 share()
19 ) 22 )
20} 23}
diff --git a/client/src/app/shared/shared-search/find-in-bulk.service.ts b/client/src/app/shared/shared-search/find-in-bulk.service.ts
index 6d77941d3..30cddc154 100644
--- a/client/src/app/shared/shared-search/find-in-bulk.service.ts
+++ b/client/src/app/shared/shared-search/find-in-bulk.service.ts
@@ -1,6 +1,6 @@
1import * as debug from 'debug' 1import * as debug from 'debug'
2import { Observable, Subject } from 'rxjs' 2import { Observable, Subject } from 'rxjs'
3import { first, map } from 'rxjs/operators' 3import { filter, first, map } from 'rxjs/operators'
4import { Injectable } from '@angular/core' 4import { Injectable } from '@angular/core'
5import { buildBulkObservable } from '@app/helpers' 5import { buildBulkObservable } from '@app/helpers'
6import { ResultList } from '@shared/models/common' 6import { ResultList } from '@shared/models/common'
@@ -12,7 +12,7 @@ const logger = debug('peertube:search:FindInBulkService')
12 12
13type BulkObservables <P extends number | string, R> = { 13type BulkObservables <P extends number | string, R> = {
14 notifier: Subject<P> 14 notifier: Subject<P>
15 result: Observable<R> 15 result: Observable<{ params: P[], response: R }>
16} 16}
17 17
18@Injectable() 18@Injectable()
@@ -70,8 +70,9 @@ export class FindInBulkService {
70 return new Observable<R>(obs => { 70 return new Observable<R>(obs => {
71 observableObject.result 71 observableObject.result
72 .pipe( 72 .pipe(
73 filter(result => result.params.includes(param)),
73 first(), 74 first(),
74 map(({ data }) => data), 75 map(result => result.response.data),
75 map(data => data.find(finder)) 76 map(data => data.find(finder))
76 ) 77 )
77 .subscribe(result => { 78 .subscribe(result => {
@@ -105,8 +106,8 @@ export class FindInBulkService {
105 return this.searchService.searchVideoPlaylists({ uuids }) 106 return this.searchService.searchVideoPlaylists({ uuids })
106 } 107 }
107 108
108 private buildBulkObservableObject <T extends number | string, R> (bulkGet: (params: T[]) => Observable<R>) { 109 private buildBulkObservableObject <P extends number | string, R> (bulkGet: (params: P[]) => Observable<R>) {
109 const notifier = new Subject<T>() 110 const notifier = new Subject<P>()
110 111
111 return { 112 return {
112 notifier, 113 notifier,
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 8d2de8173..f289fb6cf 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
@@ -37,7 +37,7 @@ export class UserSubscriptionService {
37 time: 500, 37 time: 500,
38 notifierObservable: this.existsSubject, 38 notifierObservable: this.existsSubject,
39 bulkGet: this.doSubscriptionsExist.bind(this) 39 bulkGet: this.doSubscriptionsExist.bind(this)
40 }), 40 }).pipe(map(r => r.response)),
41 41
42 this.myAccountSubscriptionCacheSubject 42 this.myAccountSubscriptionCacheSubject
43 ) 43 )
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 02632c9eb..fc291329a 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
@@ -54,7 +54,7 @@ export class VideoPlaylistService {
54 time: 500, 54 time: 500,
55 bulkGet: this.doVideosExistInPlaylist.bind(this), 55 bulkGet: this.doVideosExistInPlaylist.bind(this),
56 notifierObservable: this.videoExistsInPlaylistNotifier 56 notifierObservable: this.videoExistsInPlaylistNotifier
57 }), 57 }).pipe(map(({ response }) => response)),
58 58
59 this.videoExistsInPlaylistCacheSubject 59 this.videoExistsInPlaylistCacheSubject
60 ) 60 )