From 58497bb63f3d87a4d73cfa4e4e3b311a3235616d Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sun, 6 Dec 2020 12:38:19 +0100 Subject: [PATCH] web: fix /users/me/ endpoint being called multiple times --- web/src/api/user.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/web/src/api/user.ts b/web/src/api/user.ts index 38c5c33dc..d244327c5 100644 --- a/web/src/api/user.ts +++ b/web/src/api/user.ts @@ -1,6 +1,6 @@ import { DefaultClient, PBResponse } from "./client"; -let me: User; +let _globalMePromise: Promise; export class User { pk: number; @@ -15,10 +15,10 @@ export class User { } static me(): Promise { - if (me) { - return Promise.resolve(me); + if (!_globalMePromise) { + _globalMePromise = DefaultClient.fetch(["core", "users", "me"]); } - return DefaultClient.fetch(["core", "users", "me"]).then(u => me = u); + return _globalMePromise; } static count(): Promise {