Merge pull request #16253 from peppy/reduce-chat-overhead

Reduce overhead from chat polling when game is not active
This commit is contained in:
Dean Herbert 2022-01-01 23:42:31 +09:00 committed by GitHub
commit cf864e58f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 1 deletions

View File

@ -1,11 +1,13 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Input;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
using osu.Framework.Platform;
using osu.Game.Input.Bindings;
namespace osu.Game.Input
@ -63,8 +65,17 @@ protected override void Update()
public void OnReleased(KeyBindingReleaseEvent<GlobalAction> e) => updateLastInteractionTime();
[Resolved]
private GameHost host { get; set; }
protected override bool Handle(UIEvent e)
{
// Even when not active, `MouseMoveEvent`s will arrive.
// We don't want these to trigger a non-idle state as it's quite often the user interacting
// with other windows while osu! is in the background.
if (!host.IsActive.Value)
return base.Handle(e);
switch (e)
{
case KeyDownEvent _:

View File

@ -9,6 +9,7 @@
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,34 @@ public class ChannelManager : PollingComponent, IChannelPostTarget
public readonly BindableBool HighPollRate = new BindableBool();
private readonly IBindable<bool> isIdle = new BindableBool();
public ChannelManager()
{
CurrentChannel.ValueChanged += currentChannelChanged;
}
HighPollRate.BindValueChanged(enabled => TimeBetweenPolls.Value = enabled.NewValue ? 1000 : 6000, true);
[BackgroundDependencyLoader(permitNulls: true)]
private void load(IdleTracker idleTracker)
{
HighPollRate.BindValueChanged(updatePollRate);
isIdle.BindValueChanged(updatePollRate, true);
if (idleTracker != null)
isIdle.BindTo(idleTracker.IsIdle);
}
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>