From d0dba1fce6dcc0b91c0561eda8707c5c5bb6e626 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 25 Apr 2019 10:51:52 +0200 Subject: [PATCH] Optimize video update page load --- .../+video-edit/video-update.resolver.ts | 51 ++++++++++--------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/client/src/app/videos/+video-edit/video-update.resolver.ts b/client/src/app/videos/+video-edit/video-update.resolver.ts index 269fe3684..384458127 100644 --- a/client/src/app/videos/+video-edit/video-update.resolver.ts +++ b/client/src/app/videos/+video-edit/video-update.resolver.ts @@ -4,6 +4,7 @@ import { ActivatedRouteSnapshot, Resolve } from '@angular/router' import { map, switchMap } from 'rxjs/operators' import { VideoChannelService } from '@app/shared/video-channel/video-channel.service' import { VideoCaptionService } from '@app/shared/video-caption' +import { forkJoin } from 'rxjs' @Injectable() export class VideoUpdateResolver implements Resolve { @@ -11,35 +12,35 @@ export class VideoUpdateResolver implements Resolve { private videoService: VideoService, private videoChannelService: VideoChannelService, private videoCaptionService: VideoCaptionService - ) {} + ) { + } resolve (route: ActivatedRouteSnapshot) { const uuid: string = route.params[ 'uuid' ] return this.videoService.getVideo(uuid) - .pipe( - switchMap(video => { - return this.videoService - .loadCompleteDescription(video.descriptionPath) - .pipe(map(description => Object.assign(video, { description }))) - }), - switchMap(video => { - return this.videoChannelService - .listAccountVideoChannels(video.account) - .pipe( - map(result => result.data), - map(videoChannels => videoChannels.map(c => ({ id: c.id, label: c.displayName, support: c.support }))), - map(videoChannels => ({ video, videoChannels })) - ) - }), - switchMap(({ video, videoChannels }) => { - return this.videoCaptionService - .listCaptions(video.id) - .pipe( - map(result => result.data), - map(videoCaptions => ({ video, videoChannels, videoCaptions })) - ) - }) - ) + .pipe( + switchMap(video => { + return forkJoin([ + this.videoService + .loadCompleteDescription(video.descriptionPath) + .pipe(map(description => Object.assign(video, { description }))), + + this.videoChannelService + .listAccountVideoChannels(video.account) + .pipe( + map(result => result.data), + map(videoChannels => videoChannels.map(c => ({ id: c.id, label: c.displayName, support: c.support }))) + ), + + this.videoCaptionService + .listCaptions(video.id) + .pipe( + map(result => result.data) + ) + ]) + }), + map(([ video, videoChannels, videoCaptions ]) => ({ video, videoChannels, videoCaptions })) + ) } } -- 2.25.1