diff options
author | Chocobozzz <me@florianbigard.com> | 2020-01-06 16:13:18 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2020-01-06 16:13:26 +0100 |
commit | 218b0874ede2f0d35fdbcfb64dbe19083b0a2b04 (patch) | |
tree | 1ef2e68f11d707c4253d49df43142bee7d499aed /client/src/app/shared | |
parent | bc6f886347f676220847461600122cde86edc272 (diff) | |
download | PeerTube-218b0874ede2f0d35fdbcfb64dbe19083b0a2b04.tar.gz PeerTube-218b0874ede2f0d35fdbcfb64dbe19083b0a2b04.tar.zst PeerTube-218b0874ede2f0d35fdbcfb64dbe19083b0a2b04.zip |
Add get user cache for comments
Diffstat (limited to 'client/src/app/shared')
-rw-r--r-- | client/src/app/shared/users/user.service.ts | 14 |
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 @@ | |||
1 | import { from, Observable } from 'rxjs' | 1 | import { from, Observable, of } from 'rxjs' |
2 | import { catchError, concatMap, map, toArray } from 'rxjs/operators' | 2 | import { catchError, concatMap, map, share, shareReplay, tap, toArray } from 'rxjs/operators' |
3 | import { HttpClient, HttpParams } from '@angular/common/http' | 3 | import { HttpClient, HttpParams } from '@angular/common/http' |
4 | import { Injectable } from '@angular/core' | 4 | import { Injectable } from '@angular/core' |
5 | import { ResultList, User, UserCreate, UserRole, UserUpdate, UserUpdateMe, UserVideoQuota } from '../../../../../shared' | 5 | import { 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))) |