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