mirror of
https://github.com/osukey/osukey.git
synced 2025-08-07 00:23:59 +09:00
Add rate limiting on sending download progress updates
This commit is contained in:
@ -5,6 +5,7 @@ using System;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Logging;
|
using osu.Framework.Logging;
|
||||||
|
using osu.Framework.Threading;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
|
|
||||||
namespace osu.Game.Online.Rooms
|
namespace osu.Game.Online.Rooms
|
||||||
@ -24,12 +25,20 @@ namespace osu.Game.Online.Rooms
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public IBindable<BeatmapAvailability> Availability => availability;
|
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()
|
public OnlinePlayBeatmapAvailablilityTracker()
|
||||||
{
|
{
|
||||||
State.BindValueChanged(_ => updateAvailability());
|
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()
|
protected override void LoadComplete()
|
||||||
|
Reference in New Issue
Block a user