mirror of https://github.com/Chocobozzz/PeerTube
Fix find in bulk
parent
27c3c9456d
commit
2cc276f92f
|
@ -2,10 +2,10 @@ import { uniq } from 'lodash-es'
|
|||
import { Observable } from 'rxjs'
|
||||
import { bufferTime, distinctUntilChanged, filter, map, share, switchMap } from 'rxjs/operators'
|
||||
|
||||
function buildBulkObservable <T extends number | string, R> (options: {
|
||||
notifierObservable: Observable<T>
|
||||
function buildBulkObservable <P extends number | string, R> (options: {
|
||||
notifierObservable: Observable<P>
|
||||
time: number
|
||||
bulkGet: (params: T[]) => Observable<R>
|
||||
bulkGet: (params: P[]) => Observable<R>
|
||||
}) {
|
||||
const { notifierObservable, time, bulkGet } = options
|
||||
|
||||
|
@ -14,7 +14,10 @@ function buildBulkObservable <T extends number | string, R> (options: {
|
|||
bufferTime(time),
|
||||
filter(params => params.length !== 0),
|
||||
map(params => uniq(params)),
|
||||
switchMap(params => bulkGet(params)),
|
||||
switchMap(params => {
|
||||
return bulkGet(params)
|
||||
.pipe(map(response => ({ params, response })))
|
||||
}),
|
||||
share()
|
||||
)
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import * as debug from 'debug'
|
||||
import { Observable, Subject } from 'rxjs'
|
||||
import { first, map } from 'rxjs/operators'
|
||||
import { filter, first, map } from 'rxjs/operators'
|
||||
import { Injectable } from '@angular/core'
|
||||
import { buildBulkObservable } from '@app/helpers'
|
||||
import { ResultList } from '@shared/models/common'
|
||||
|
@ -12,7 +12,7 @@ const logger = debug('peertube:search:FindInBulkService')
|
|||
|
||||
type BulkObservables <P extends number | string, R> = {
|
||||
notifier: Subject<P>
|
||||
result: Observable<R>
|
||||
result: Observable<{ params: P[], response: R }>
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
|
@ -70,8 +70,9 @@ export class FindInBulkService {
|
|||
return new Observable<R>(obs => {
|
||||
observableObject.result
|
||||
.pipe(
|
||||
filter(result => result.params.includes(param)),
|
||||
first(),
|
||||
map(({ data }) => data),
|
||||
map(result => result.response.data),
|
||||
map(data => data.find(finder))
|
||||
)
|
||||
.subscribe(result => {
|
||||
|
@ -105,8 +106,8 @@ export class FindInBulkService {
|
|||
return this.searchService.searchVideoPlaylists({ uuids })
|
||||
}
|
||||
|
||||
private buildBulkObservableObject <T extends number | string, R> (bulkGet: (params: T[]) => Observable<R>) {
|
||||
const notifier = new Subject<T>()
|
||||
private buildBulkObservableObject <P extends number | string, R> (bulkGet: (params: P[]) => Observable<R>) {
|
||||
const notifier = new Subject<P>()
|
||||
|
||||
return {
|
||||
notifier,
|
||||
|
|
|
@ -37,7 +37,7 @@ export class UserSubscriptionService {
|
|||
time: 500,
|
||||
notifierObservable: this.existsSubject,
|
||||
bulkGet: this.doSubscriptionsExist.bind(this)
|
||||
}),
|
||||
}).pipe(map(r => r.response)),
|
||||
|
||||
this.myAccountSubscriptionCacheSubject
|
||||
)
|
||||
|
|
|
@ -54,7 +54,7 @@ export class VideoPlaylistService {
|
|||
time: 500,
|
||||
bulkGet: this.doVideosExistInPlaylist.bind(this),
|
||||
notifierObservable: this.videoExistsInPlaylistNotifier
|
||||
}),
|
||||
}).pipe(map(({ response }) => response)),
|
||||
|
||||
this.videoExistsInPlaylistCacheSubject
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue