Skip to content

Commit

Permalink
Further reduce calls of API.getCurrentUser (vrcx-team#899)
Browse files Browse the repository at this point in the history
* Move nextCurrentUserRefresh set into API.getCurrentUser

* Fix loop reset

* Don't get user on refreshFriends too fast
  • Loading branch information
DubyaDude authored and Natsumi-sama committed Sep 10, 2024
1 parent a6946f0 commit c141a40
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions html/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -1909,6 +1909,7 @@ speechSynthesis.getVoices();
};

API.getCurrentUser = function () {
$app.nextCurrentUserRefresh = 840; // 7mins
return this.call('auth/user', {
method: 'GET'
}).then((json) => {
Expand Down Expand Up @@ -5789,15 +5790,13 @@ 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) {
API.refreshPlayerModerations();
}
}
if (--this.nextCurrentUserRefresh <= 0) {
this.nextCurrentUserRefresh = 840; // 7mins
API.getCurrentUser();
}
if (--this.nextGroupInstanceRefresh <= 0) {
Expand Down Expand Up @@ -9135,10 +9134,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();
};
Expand Down

0 comments on commit c141a40

Please sign in to comment.