1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 22:07:25 +08:00

Add rate limiting on sending download progress updates

This commit is contained in:
Dean Herbert 2021-02-05 17:34:05 +09:00
parent 110458612d
commit dad32da415

View File

@ -5,6 +5,7 @@ using System;
using System.Linq;
using osu.Framework.Bindables;
using osu.Framework.Logging;
using osu.Framework.Threading;
using osu.Game.Beatmaps;
namespace osu.Game.Online.Rooms
@ -24,12 +25,20 @@ namespace osu.Game.Online.Rooms
/// </summary>
public IBindable<BeatmapAvailability> Availability => availability;
private readonly Bindable<BeatmapAvailability> availability = new Bindable<BeatmapAvailability>();
private readonly Bindable<BeatmapAvailability> availability = new Bindable<BeatmapAvailability>(BeatmapAvailability.LocallyAvailable());
private ScheduledDelegate progressUpdate;
public OnlinePlayBeatmapAvailablilityTracker()
{
State.BindValueChanged(_ => updateAvailability());
Progress.BindValueChanged(_ => updateAvailability(), true);
Progress.BindValueChanged(_ =>
{
// incoming progress changes are going to be at a very high rate.
// we don't want to flood the network with this, so rate limit how often we send progress updates.
if (progressUpdate?.Completed != false)
progressUpdate = Scheduler.AddDelayed(updateAvailability, progressUpdate == null ? 0 : 500);
});
}
protected override void LoadComplete()