Fix find in bulk

pull/4468/head
Chocobozzz 2021-10-18 11:44:54 +02:00
parent 27c3c9456d
commit 2cc276f92f
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
4 changed files with 15 additions and 11 deletions

View File

@ -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()
)
}

View File

@ -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,

View File

@ -37,7 +37,7 @@ export class UserSubscriptionService {
time: 500,
notifierObservable: this.existsSubject,
bulkGet: this.doSubscriptionsExist.bind(this)
}),
}).pipe(map(r => r.response)),
this.myAccountSubscriptionCacheSubject
)

View File

@ -54,7 +54,7 @@ export class VideoPlaylistService {
time: 500,
bulkGet: this.doVideosExistInPlaylist.bind(this),
notifierObservable: this.videoExistsInPlaylistNotifier
}),
}).pipe(map(({ response }) => response)),
this.videoExistsInPlaylistCacheSubject
)