From 6b0c3c7ca917ad09a011c2821f5bd1a2485aebca Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 9 Jan 2020 09:26:59 +0100 Subject: Optimize list my playlists SQL query --- .../src/app/shared/video-playlist/video-playlist.service.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'client') 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 1ec9315ef..078bcc5d7 100644 --- a/client/src/app/shared/video-playlist/video-playlist.service.ts +++ b/client/src/app/shared/video-playlist/video-playlist.service.ts @@ -42,6 +42,7 @@ export class VideoPlaylistService { private videoExistsCache: { [ id: number ]: VideoExistInPlaylist[] } = {} private myAccountPlaylistCache: ResultList = undefined + private myAccountPlaylistCacheRunning = false private myAccountPlaylistCacheSubject = new Subject>() constructor ( @@ -78,12 +79,20 @@ export class VideoPlaylistService { } listMyPlaylistWithCache (user: AuthUser, search?: string) { - if (!search && this.myAccountPlaylistCache) return of(this.myAccountPlaylistCache) + if (!search) { + if (this.myAccountPlaylistCacheRunning) return + if (this.myAccountPlaylistCache) return of(this.myAccountPlaylistCache) + } + + this.myAccountPlaylistCacheRunning = true return this.listAccountPlaylists(user.account, undefined, '-updatedAt', search) .pipe( tap(result => { - if (!search) this.myAccountPlaylistCache = result + if (!search) { + this.myAccountPlaylistCacheRunning = false + this.myAccountPlaylistCache = result + } }) ) } -- cgit v1.2.3