mirror of
https://github.com/ppy/osu.git
synced 2024-12-13 08:32:57 +08:00
Add change ingester to handle passing of online changes to correct target components
This commit is contained in:
parent
cd39f444ef
commit
6adcf82d2e
52
osu.Game/Beatmaps/BeatmapOnlineChangeIngest.cs
Normal file
52
osu.Game/Beatmaps/BeatmapOnlineChangeIngest.cs
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
|
#nullable enable
|
||||||
|
|
||||||
|
using System.Linq;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Game.Database;
|
||||||
|
using osu.Game.Online.Metadata;
|
||||||
|
|
||||||
|
namespace osu.Game.Beatmaps
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Ingests any changes that happen externally to the client, reprocessing as required.
|
||||||
|
/// </summary>
|
||||||
|
public class BeatmapOnlineChangeIngest : Component
|
||||||
|
{
|
||||||
|
private readonly BeatmapUpdater beatmapUpdater;
|
||||||
|
private readonly RealmAccess realm;
|
||||||
|
private readonly MetadataClient metadataClient;
|
||||||
|
|
||||||
|
public BeatmapOnlineChangeIngest(BeatmapUpdater beatmapUpdater, RealmAccess realm, MetadataClient metadataClient)
|
||||||
|
{
|
||||||
|
this.beatmapUpdater = beatmapUpdater;
|
||||||
|
this.realm = realm;
|
||||||
|
this.metadataClient = metadataClient;
|
||||||
|
|
||||||
|
metadataClient.ChangedBeatmapSetsArrived += changesDetected;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void changesDetected(int[] beatmapSetIds)
|
||||||
|
{
|
||||||
|
// May want to batch incoming updates further if the background realm operations ever becomes a concern.
|
||||||
|
realm.Run(r =>
|
||||||
|
{
|
||||||
|
foreach (int id in beatmapSetIds)
|
||||||
|
{
|
||||||
|
var matchingSet = r.All<BeatmapSetInfo>().FirstOrDefault(s => s.OnlineID == id);
|
||||||
|
|
||||||
|
if (matchingSet != null)
|
||||||
|
beatmapUpdater.Queue(matchingSet.ToLive(realm));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Dispose(bool isDisposing)
|
||||||
|
{
|
||||||
|
base.Dispose(isDisposing);
|
||||||
|
metadataClient.ChangedBeatmapSetsArrived -= changesDetected;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -6,6 +6,7 @@ using System.Diagnostics;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using osu.Framework.Extensions.ObjectExtensions;
|
using osu.Framework.Extensions.ObjectExtensions;
|
||||||
|
using osu.Framework.Logging;
|
||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
using osu.Game.Database;
|
using osu.Game.Database;
|
||||||
using osu.Game.Online.API;
|
using osu.Game.Online.API;
|
||||||
@ -30,21 +31,12 @@ namespace osu.Game.Beatmaps
|
|||||||
onlineLookupQueue = new BeatmapOnlineLookupQueue(api, storage);
|
onlineLookupQueue = new BeatmapOnlineLookupQueue(api, storage);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Queue a beatmap for background processing.
|
|
||||||
/// </summary>
|
|
||||||
public void Queue(int beatmapSetId)
|
|
||||||
{
|
|
||||||
// TODO: implement
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Queue a beatmap for background processing.
|
/// Queue a beatmap for background processing.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Queue(Live<BeatmapSetInfo> beatmap)
|
public void Queue(Live<BeatmapSetInfo> beatmap)
|
||||||
{
|
{
|
||||||
// For now, just fire off a task.
|
Logger.Log($"Queueing change for local beatmap {beatmap}");
|
||||||
// TODO: Add actual queueing probably.
|
|
||||||
Task.Factory.StartNew(() => beatmap.PerformRead(Process));
|
Task.Factory.StartNew(() => beatmap.PerformRead(Process));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -289,6 +289,8 @@ namespace osu.Game
|
|||||||
dependencies.CacheAs(multiplayerClient = new OnlineMultiplayerClient(endpoints));
|
dependencies.CacheAs(multiplayerClient = new OnlineMultiplayerClient(endpoints));
|
||||||
dependencies.CacheAs(metadataClient = new OnlineMetadataClient(endpoints));
|
dependencies.CacheAs(metadataClient = new OnlineMetadataClient(endpoints));
|
||||||
|
|
||||||
|
AddInternal(new BeatmapOnlineChangeIngest(beatmapUpdater, realm, metadataClient));
|
||||||
|
|
||||||
BeatmapManager.ProcessBeatmap = set => beatmapUpdater.Process(set);
|
BeatmapManager.ProcessBeatmap = set => beatmapUpdater.Process(set);
|
||||||
|
|
||||||
dependencies.Cache(userCache = new UserLookupCache());
|
dependencies.Cache(userCache = new UserLookupCache());
|
||||||
|
Loading…
Reference in New Issue
Block a user