1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 07:33:20 +08:00

Further reduce chat poll rate when idle or not visible

This commit is contained in:
Dean Herbert 2021-12-26 16:26:47 +09:00
parent e448c28cad
commit 7c25ce81e1

View File

@ -9,6 +9,7 @@ using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Logging;
using osu.Game.Database;
using osu.Game.Input;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Online.API.Requests.Responses;
@ -67,11 +68,33 @@ namespace osu.Game.Online.Chat
public readonly BindableBool HighPollRate = new BindableBool();
private IBindable<bool> isIdle;
public ChannelManager()
{
CurrentChannel.ValueChanged += currentChannelChanged;
}
HighPollRate.BindValueChanged(enabled => TimeBetweenPolls.Value = enabled.NewValue ? 1000 : 6000, true);
[BackgroundDependencyLoader]
private void load(IdleTracker idleTracker)
{
HighPollRate.BindValueChanged(updatePollRate);
isIdle = idleTracker.IsIdle.GetBoundCopy();
isIdle.BindValueChanged(updatePollRate, true);
}
private void updatePollRate(ValueChangedEvent<bool> valueChangedEvent)
{
// Polling will eventually be replaced with websocket, but let's avoid doing these background operations as much as possible for now.
// The only loss will be delayed PM/message highlight notifications.
if (HighPollRate.Value)
TimeBetweenPolls.Value = 1000;
else if (!isIdle.Value)
TimeBetweenPolls.Value = 60000;
else
TimeBetweenPolls.Value = 600000;
}
/// <summary>