From f44a284a3e863cac144d1675208a38422ac0fc8c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 9 Jan 2020 14:06:29 +0100 Subject: Fix playlist observable cache --- .../app/shared/video-playlist/video-playlist.service.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/client/src/app/shared/video-playlist/video-playlist.service.ts b/client/src/app/shared/video-playlist/video-playlist.service.ts index 078bcc5d7..fc5eb5337 100644 --- a/client/src/app/shared/video-playlist/video-playlist.service.ts +++ b/client/src/app/shared/video-playlist/video-playlist.service.ts @@ -42,7 +42,7 @@ export class VideoPlaylistService { private videoExistsCache: { [ id: number ]: VideoExistInPlaylist[] } = {} private myAccountPlaylistCache: ResultList = undefined - private myAccountPlaylistCacheRunning = false + private myAccountPlaylistCacheRunning: Observable> private myAccountPlaylistCacheSubject = new Subject>() constructor ( @@ -80,21 +80,23 @@ export class VideoPlaylistService { listMyPlaylistWithCache (user: AuthUser, search?: string) { if (!search) { - if (this.myAccountPlaylistCacheRunning) return + if (this.myAccountPlaylistCacheRunning) return this.myAccountPlaylistCacheRunning if (this.myAccountPlaylistCache) return of(this.myAccountPlaylistCache) } - this.myAccountPlaylistCacheRunning = true - - return this.listAccountPlaylists(user.account, undefined, '-updatedAt', search) + const obs = this.listAccountPlaylists(user.account, undefined, '-updatedAt', search) .pipe( tap(result => { if (!search) { - this.myAccountPlaylistCacheRunning = false + this.myAccountPlaylistCacheRunning = undefined this.myAccountPlaylistCache = result } - }) + }), + share() ) + + if (!search) this.myAccountPlaylistCacheRunning = obs + return obs } listAccountPlaylists ( -- cgit v1.2.3