Add better log output and sleeping during gameplay sections

This commit is contained in:
Dean Herbert 2022-07-21 03:55:05 +09:00
parent 57a41c6897
commit 04f48d8862
1 changed files with 18 additions and 3 deletions

View File

@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
@ -13,6 +14,7 @@
using osu.Game.Beatmaps;
using osu.Game.Database;
using osu.Game.Rulesets;
using osu.Game.Screens.Play;
namespace osu.Game
{
@ -30,6 +32,9 @@ public class BackgroundBeatmapProcessor : Component
[Resolved]
private IBindable<WorkingBeatmap> gameBeatmap { get; set; } = null!;
[Resolved]
private ILocalUserPlayInfo? localUserPlayInfo { get; set; }
protected override void LoadComplete()
{
base.LoadComplete();
@ -81,10 +86,10 @@ private void checkForOutdatedStarRatings()
private void processBeatmapSetsWithMissingMetrics()
{
// TODO: rate limit and pause processing during gameplay.
HashSet<Guid> beatmapSetIds = new HashSet<Guid>();
Logger.Log("Querying for beatmap sets to reprocess...");
realmAccess.Run(r =>
{
foreach (var b in r.All<BeatmapInfo>().Where(b => b.StarRating == 0 || (b.OnlineID > 0 && b.LastOnlineUpdate == null)))
@ -94,15 +99,25 @@ private void processBeatmapSetsWithMissingMetrics()
}
});
Logger.Log($"Found {beatmapSetIds.Count} beatmap sets which require reprocessing.");
int i = 0;
foreach (var id in beatmapSetIds)
{
while (localUserPlayInfo?.IsPlaying.Value == true)
{
Logger.Log("Background processing sleeping 30s due to active gameplay...");
Thread.Sleep(30000);
}
realmAccess.Run(r =>
{
var set = r.Find<BeatmapSetInfo>(id);
if (set != null)
{
Logger.Log($"Background processing {set}");
Logger.Log($"Background processing {set} ({++i} / {beatmapSetIds.Count})");
beatmapUpdater.Process(set);
}
});