mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 11:00:48 +03:00
Throttle sync processing if the window is unfocused for a while
This commit is contained in:
parent
7823aceb58
commit
aeda42111b
2 changed files with 26 additions and 3 deletions
|
@ -844,6 +844,9 @@ ChatPage::handleSyncResponse(const mtx::responses::Sync &res, const std::string
|
||||||
nhlog::db()->error("saving sync response: {}", e.what());
|
nhlog::db()->error("saving sync response: {}", e.what());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (shouldThrottleSync())
|
||||||
|
QTimer::singleShot(1000, this, &ChatPage::trySyncCb);
|
||||||
|
else
|
||||||
emit trySyncCb();
|
emit trySyncCb();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1161,6 +1164,20 @@ ChatPage::setStatus(const QString &status)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
ChatPage::shouldBeUnavailable() const
|
||||||
|
{
|
||||||
|
return lastWindowActive.isValid() &&
|
||||||
|
lastWindowActive.addSecs(60 * 5) < QDateTime::currentDateTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
ChatPage::shouldThrottleSync() const
|
||||||
|
{
|
||||||
|
return lastWindowActive.isValid() &&
|
||||||
|
lastWindowActive.addSecs(6 * 5) < QDateTime::currentDateTime();
|
||||||
|
}
|
||||||
|
|
||||||
mtx::presence::PresenceState
|
mtx::presence::PresenceState
|
||||||
ChatPage::currentPresence() const
|
ChatPage::currentPresence() const
|
||||||
{
|
{
|
||||||
|
@ -1172,8 +1189,7 @@ ChatPage::currentPresence() const
|
||||||
case UserSettings::Presence::Offline:
|
case UserSettings::Presence::Offline:
|
||||||
return mtx::presence::offline;
|
return mtx::presence::offline;
|
||||||
case UserSettings::Presence::AutomaticPresence:
|
case UserSettings::Presence::AutomaticPresence:
|
||||||
if (lastWindowActive.isValid() &&
|
if (shouldBeUnavailable())
|
||||||
lastWindowActive.addSecs(60 * 5) < QDateTime::currentDateTime())
|
|
||||||
return mtx::presence::unavailable;
|
return mtx::presence::unavailable;
|
||||||
else
|
else
|
||||||
return mtx::presence::online;
|
return mtx::presence::online;
|
||||||
|
|
|
@ -203,6 +203,13 @@ private:
|
||||||
void loadStateFromCache();
|
void loadStateFromCache();
|
||||||
void resetUI();
|
void resetUI();
|
||||||
|
|
||||||
|
// returns if the user had no interaction with Nheko for quite a while, which means we set our
|
||||||
|
// presence to unavailable if automatic presence is enabled
|
||||||
|
bool shouldBeUnavailable() const;
|
||||||
|
// If we should throttle sync processing to reduce CPU load, if people are spamming messages and
|
||||||
|
// we aren't looking
|
||||||
|
bool shouldThrottleSync() const;
|
||||||
|
|
||||||
template<class Collection>
|
template<class Collection>
|
||||||
Memberships getMemberships(const std::vector<Collection> &events) const;
|
Memberships getMemberships(const std::vector<Collection> &events) const;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue