From 2cc276f92fefeff88fcc74217e1174a3ddb3f074 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 18 Oct 2021 11:44:54 +0200 Subject: [PATCH] Fix find in bulk --- client/src/app/helpers/rxjs.ts | 11 +++++++---- .../app/shared/shared-search/find-in-bulk.service.ts | 11 ++++++----- .../user-subscription.service.ts | 2 +- .../shared-video-playlist/video-playlist.service.ts | 2 +- 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' import { Observable } from 'rxjs' import { bufferTime, distinctUntilChanged, filter, map, share, switchMap } from 'rxjs/operators' -function buildBulkObservable (options: { - notifierObservable: Observable +function buildBulkObservable

(options: { + notifierObservable: Observable

time: number - bulkGet: (params: T[]) => Observable + bulkGet: (params: P[]) => Observable }) { const { notifierObservable, time, bulkGet } = options @@ -14,7 +14,10 @@ function buildBulkObservable (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() ) } 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 @@ 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

= { notifier: Subject

- result: Observable + result: Observable<{ params: P[], response: R }> } @Injectable() @@ -70,8 +70,9 @@ export class FindInBulkService { return new Observable(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 (bulkGet: (params: T[]) => Observable) { - const notifier = new Subject() + private buildBulkObservableObject

(bulkGet: (params: P[]) => Observable) { + const notifier = new Subject

() return { 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 { time: 500, notifierObservable: this.existsSubject, bulkGet: this.doSubscriptionsExist.bind(this) - }), + }).pipe(map(r => r.response)), this.myAccountSubscriptionCacheSubject ) 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 { time: 500, bulkGet: this.doVideosExistInPlaylist.bind(this), notifierObservable: this.videoExistsInPlaylistNotifier - }), + }).pipe(map(({ response }) => response)), this.videoExistsInPlaylistCacheSubject )