web: fix /users/me/ endpoint being called multiple times

This commit is contained in:
Jens Langhammer 2020-12-06 12:38:19 +01:00
parent e0bc4f1da5
commit 58497bb63f
1 changed files with 4 additions and 4 deletions

View File

@ -1,6 +1,6 @@
import { DefaultClient, PBResponse } from "./client";
let me: User;
let _globalMePromise: Promise<User>;
export class User {
pk: number;
@ -15,10 +15,10 @@ export class User {
}
static me(): Promise<User> {
if (me) {
return Promise.resolve<User>(me);
if (!_globalMePromise) {
_globalMePromise = DefaultClient.fetch<User>(["core", "users", "me"]);
}
return DefaultClient.fetch<User>(["core", "users", "me"]).then(u => me = u);
return _globalMePromise;
}
static count(): Promise<number> {