Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Further reduce calls of API.getCurrentUser #899

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions html/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -1905,6 +1905,7 @@ speechSynthesis.getVoices();
};

API.getCurrentUser = function () {
$app.nextCurrentUserRefresh = 840; // 7mins
return this.call('auth/user', {
method: 'GET'
}).then((json) => {
Expand Down Expand Up @@ -5773,15 +5774,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 @@ -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();
};
Expand Down