]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Fix playlist observable cache
authorChocobozzz <me@florianbigard.com>
Thu, 9 Jan 2020 13:06:29 +0000 (14:06 +0100)
committerChocobozzz <me@florianbigard.com>
Thu, 9 Jan 2020 13:06:29 +0000 (14:06 +0100)
client/src/app/shared/video-playlist/video-playlist.service.ts

index 078bcc5d78bdcdce6ff42c60125197f15639cda1..fc5eb5337e518a8278747acfee6a2988cbca9bf2 100644 (file)
@@ -42,7 +42,7 @@ export class VideoPlaylistService {
   private videoExistsCache: { [ id: number ]: VideoExistInPlaylist[] } = {}
 
   private myAccountPlaylistCache: ResultList<CachedPlaylist> = undefined
-  private myAccountPlaylistCacheRunning = false
+  private myAccountPlaylistCacheRunning: Observable<ResultList<CachedPlaylist>>
   private myAccountPlaylistCacheSubject = new Subject<ResultList<CachedPlaylist>>()
 
   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 (