Fix playlist observable cache

pull/2396/head
Chocobozzz 2020-01-09 14:06:29 +01:00
parent c4a1811ea8
commit f44a284a3e
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
1 changed files with 9 additions and 7 deletions

View 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 (