Save last processed id to config for now

This commit is contained in:
Dean Herbert 2022-07-05 21:42:35 +09:00
parent 59d0bac728
commit bdd1bf4da0
5 changed files with 16 additions and 10 deletions

View File

@ -167,6 +167,8 @@ protected override void InitialiseDefaults()
SetDefault(OsuSetting.DiscordRichPresence, DiscordRichPresenceMode.Full);
SetDefault(OsuSetting.EditorWaveformOpacity, 0.25f);
SetDefault(OsuSetting.LastProcessedMetadataId, -1);
}
public IDictionary<OsuSetting, string> GetLoggableState() =>
@ -363,5 +365,6 @@ public enum OsuSetting
DiscordRichPresence,
AutomaticallyDownloadWhenSpectating,
ShowOnlineExplicitContent,
LastProcessedMetadataId
}
}

View File

@ -17,9 +17,9 @@ public class BeatmapUpdates
public int[] BeatmapSetIDs { get; set; }
[Key(1)]
public uint LastProcessedQueueID { get; set; }
public int LastProcessedQueueID { get; set; }
public BeatmapUpdates(int[] beatmapSetIDs, uint lastProcessedQueueID)
public BeatmapUpdates(int[] beatmapSetIDs, int lastProcessedQueueID)
{
BeatmapSetIDs = beatmapSetIDs;
LastProcessedQueueID = lastProcessedQueueID;

View File

@ -16,6 +16,6 @@ public interface IMetadataServer
/// </summary>
/// <param name="queueId">The last processed queue ID.</param>
/// <returns></returns>
Task<BeatmapUpdates> GetChangesSince(uint queueId);
Task<BeatmapUpdates> GetChangesSince(int queueId);
}
}

View File

@ -10,6 +10,6 @@ public abstract class MetadataClient : Component, IMetadataClient, IMetadataServ
{
public abstract Task BeatmapSetsUpdated(BeatmapUpdates updates);
public abstract Task<BeatmapUpdates> GetChangesSince(uint queueId);
public abstract Task<BeatmapUpdates> GetChangesSince(int queueId);
}
}

View File

@ -8,6 +8,7 @@
using osu.Framework.Bindables;
using osu.Framework.Logging;
using osu.Game.Beatmaps;
using osu.Game.Configuration;
using osu.Game.Online.API;
namespace osu.Game.Online.Metadata
@ -19,7 +20,7 @@ public class OnlineMetadataClient : MetadataClient
private IHubClientConnector? connector;
private uint? lastQueueId;
private Bindable<int> lastQueueId = null!;
private HubConnection? connection => connector?.CurrentConnection;
@ -30,7 +31,7 @@ public OnlineMetadataClient(EndpointConfiguration endpoints, BeatmapUpdater beat
}
[BackgroundDependencyLoader]
private void load(IAPIProvider api)
private void load(IAPIProvider api, OsuConfigManager config)
{
// Importantly, we are intentionally not using MessagePack here to correctly support derived class serialization.
// More information on the limitations / reasoning can be found in osu-server-spectator's initialisation code.
@ -47,6 +48,8 @@ private void load(IAPIProvider api)
connector.IsConnected.BindValueChanged(isConnectedChanged, true);
}
lastQueueId = config.GetBindable<int>(OsuSetting.LastProcessedMetadataId);
}
private bool catchingUp;
@ -56,7 +59,7 @@ private void isConnectedChanged(ValueChangedEvent<bool> connected)
if (!connected.NewValue)
return;
if (lastQueueId != null)
if (lastQueueId.Value >= 0)
{
catchingUp = true;
@ -69,7 +72,7 @@ private void isConnectedChanged(ValueChangedEvent<bool> connected)
Logger.Log($"Requesting catch-up from {lastQueueId.Value}");
var catchUpChanges = await GetChangesSince(lastQueueId.Value);
lastQueueId = catchUpChanges.LastProcessedQueueID;
lastQueueId.Value = catchUpChanges.LastProcessedQueueID;
if (catchUpChanges.BeatmapSetIDs.Length == 0)
{
@ -94,7 +97,7 @@ public override async Task BeatmapSetsUpdated(BeatmapUpdates updates)
// If we're still catching up, avoid updating the last ID as it will interfere with catch-up efforts.
if (!catchingUp)
lastQueueId = updates.LastProcessedQueueID;
lastQueueId.Value = updates.LastProcessedQueueID;
await ProcessChanges(updates.BeatmapSetIDs);
}
@ -110,7 +113,7 @@ protected Task ProcessChanges(int[] beatmapSetIDs)
return Task.CompletedTask;
}
public override Task<BeatmapUpdates> GetChangesSince(uint queueId)
public override Task<BeatmapUpdates> GetChangesSince(int queueId)
{
if (connector?.IsConnected.Value != true)
return Task.FromCanceled<BeatmapUpdates>(default);