From: Chocobozzz Date: Thu, 9 Jan 2020 13:06:29 +0000 (+0100) Subject: Fix playlist observable cache X-Git-Tag: v2.1.0-rc.1~53 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=f44a284a3e863cac144d1675208a38422ac0fc8c;p=oweals%2Fpeertube.git Fix playlist observable cache --- 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 (