From: Chocobozzz Date: Mon, 6 Jan 2020 15:13:18 +0000 (+0100) Subject: Add get user cache for comments X-Git-Tag: v2.1.0-rc.1~100 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=218b0874ede2f0d35fdbcfb64dbe19083b0a2b04;p=oweals%2Fpeertube.git Add get user cache for comments --- diff --git a/client/src/app/shared/users/user.service.ts b/client/src/app/shared/users/user.service.ts index 051e0bfa4..e24d91df3 100644 --- a/client/src/app/shared/users/user.service.ts +++ b/client/src/app/shared/users/user.service.ts @@ -1,5 +1,5 @@ -import { from, Observable } from 'rxjs' -import { catchError, concatMap, map, toArray } from 'rxjs/operators' +import { from, Observable, of } from 'rxjs' +import { catchError, concatMap, map, share, shareReplay, tap, toArray } from 'rxjs/operators' import { HttpClient, HttpParams } from '@angular/common/http' import { Injectable } from '@angular/core' import { ResultList, User, UserCreate, UserRole, UserUpdate, UserUpdateMe, UserVideoQuota } from '../../../../../shared' @@ -17,6 +17,8 @@ export class UserService { private bytesPipe = new BytesPipe() + private userCache: { [ id: number ]: Observable } = {} + constructor ( private authHttp: HttpClient, private restExtractor: RestExtractor, @@ -194,6 +196,14 @@ export class UserService { ) } + getUserWithCache (userId: number) { + if (!this.userCache[userId]) { + this.userCache[ userId ] = this.getUser(userId).pipe(shareReplay()) + } + + return this.userCache[userId] + } + getUser (userId: number) { return this.authHttp.get(UserService.BASE_USERS_URL + userId) .pipe(catchError(err => this.restExtractor.handleError(err))) diff --git a/client/src/app/videos/+video-watch/comment/video-comment.component.html b/client/src/app/videos/+video-watch/comment/video-comment.component.html index 4753641bd..246a08435 100644 --- a/client/src/app/videos/+video-watch/comment/video-comment.component.html +++ b/client/src/app/videos/+video-watch/comment/video-comment.component.html @@ -36,8 +36,9 @@
Reply
Delete
+
@@ -80,8 +81,8 @@ > - - + + diff --git a/client/src/app/videos/+video-watch/comment/video-comment.component.ts b/client/src/app/videos/+video-watch/comment/video-comment.component.ts index 8c376d654..0c18b6e5d 100644 --- a/client/src/app/videos/+video-watch/comment/video-comment.component.ts +++ b/client/src/app/videos/+video-watch/comment/video-comment.component.ts @@ -107,7 +107,7 @@ export class VideoCommentComponent implements OnInit, OnChanges { const user = this.authService.getUser() if (user.hasRight(UserRight.MANAGE_USERS)) { - this.userService.getUser(account.userId) + this.userService.getUserWithCache(account.userId) .subscribe( user => this.commentUser = user,