From 0b8d394a11dcdd47eab0c7c92b37030d86f62c74 Mon Sep 17 00:00:00 2001 From: Usman Shafiq Date: Tue, 10 Sep 2024 16:38:22 -0400 Subject: [PATCH] Further reduce calls of API.getCurrentUser (#899) * Move nextCurrentUserRefresh set into API.getCurrentUser * Fix loop reset * Don't get user on refreshFriends too fast --- html/src/app.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/html/src/app.js b/html/src/app.js index cca36936..6f6ecbc3 100644 --- a/html/src/app.js +++ b/html/src/app.js @@ -1905,6 +1905,7 @@ speechSynthesis.getVoices(); }; API.getCurrentUser = function () { + $app.nextCurrentUserRefresh = 840; // 7mins return this.call('auth/user', { method: 'GET' }).then((json) => { @@ -5773,7 +5774,6 @@ speechSynthesis.getVoices(); if (API.isLoggedIn === true) { if (--this.nextFriendsRefresh <= 0) { this.nextFriendsRefresh = 7200; // 1hour - this.nextCurrentUserRefresh = 840; // 7mins this.refreshFriendsList(); this.updateStoredUser(API.currentUser); if (this.isGameRunning) { @@ -5781,7 +5781,6 @@ speechSynthesis.getVoices(); } } if (--this.nextCurrentUserRefresh <= 0) { - this.nextCurrentUserRefresh = 840; // 7mins API.getCurrentUser(); } if (--this.nextGroupInstanceRefresh <= 0) { @@ -9118,10 +9117,13 @@ speechSynthesis.getVoices(); }); $app.methods.refreshFriendsList = async function () { - await API.getCurrentUser().catch((err) => { - console.error(err); - }); - this.nextCurrentUserRefresh = 840; // 7mins + // If we just got user less then 1 min before code call, don't call it again + if ($app.nextCurrentUserRefresh < 720) + { + await API.getCurrentUser().catch((err) => { + console.error(err); + }); + } await API.refreshFriends(); API.reconnectWebSocket(); };