aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/users/user.service.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/shared/users/user.service.ts')
-rw-r--r--client/src/app/shared/users/user.service.ts14
1 files changed, 12 insertions, 2 deletions
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 @@
1import { from, Observable } from 'rxjs' 1import { from, Observable, of } from 'rxjs'
2import { catchError, concatMap, map, toArray } from 'rxjs/operators' 2import { catchError, concatMap, map, share, shareReplay, tap, toArray } from 'rxjs/operators'
3import { HttpClient, HttpParams } from '@angular/common/http' 3import { HttpClient, HttpParams } from '@angular/common/http'
4import { Injectable } from '@angular/core' 4import { Injectable } from '@angular/core'
5import { ResultList, User, UserCreate, UserRole, UserUpdate, UserUpdateMe, UserVideoQuota } from '../../../../../shared' 5import { ResultList, User, UserCreate, UserRole, UserUpdate, UserUpdateMe, UserVideoQuota } from '../../../../../shared'
@@ -17,6 +17,8 @@ export class UserService {
17 17
18 private bytesPipe = new BytesPipe() 18 private bytesPipe = new BytesPipe()
19 19
20 private userCache: { [ id: number ]: Observable<User> } = {}
21
20 constructor ( 22 constructor (
21 private authHttp: HttpClient, 23 private authHttp: HttpClient,
22 private restExtractor: RestExtractor, 24 private restExtractor: RestExtractor,
@@ -194,6 +196,14 @@ export class UserService {
194 ) 196 )
195 } 197 }
196 198
199 getUserWithCache (userId: number) {
200 if (!this.userCache[userId]) {
201 this.userCache[ userId ] = this.getUser(userId).pipe(shareReplay())
202 }
203
204 return this.userCache[userId]
205 }
206
197 getUser (userId: number) { 207 getUser (userId: number) {
198 return this.authHttp.get<User>(UserService.BASE_USERS_URL + userId) 208 return this.authHttp.get<User>(UserService.BASE_USERS_URL + userId)
199 .pipe(catchError(err => this.restExtractor.handleError(err))) 209 .pipe(catchError(err => this.restExtractor.handleError(err)))