mirror of
https://github.com/osukey/osukey.git
synced 2025-05-03 04:37:30 +09:00
Move scheduler from OnlineLookupQueue
to BeatmapUpdater
This commit is contained in:
parent
fe6b487d75
commit
17a3fd30fb
@ -8,6 +8,7 @@ using System.Threading.Tasks;
|
|||||||
using osu.Framework.Extensions.ObjectExtensions;
|
using osu.Framework.Extensions.ObjectExtensions;
|
||||||
using osu.Framework.Logging;
|
using osu.Framework.Logging;
|
||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
|
using osu.Framework.Threading;
|
||||||
using osu.Game.Database;
|
using osu.Game.Database;
|
||||||
using osu.Game.Online.API;
|
using osu.Game.Online.API;
|
||||||
using osu.Game.Rulesets.Objects;
|
using osu.Game.Rulesets.Objects;
|
||||||
@ -20,15 +21,21 @@ namespace osu.Game.Beatmaps
|
|||||||
public class BeatmapUpdater : IDisposable
|
public class BeatmapUpdater : IDisposable
|
||||||
{
|
{
|
||||||
private readonly IWorkingBeatmapCache workingBeatmapCache;
|
private readonly IWorkingBeatmapCache workingBeatmapCache;
|
||||||
private readonly BeatmapOnlineLookupQueue onlineLookupQueue;
|
|
||||||
private readonly BeatmapDifficultyCache difficultyCache;
|
private readonly BeatmapDifficultyCache difficultyCache;
|
||||||
|
|
||||||
|
private readonly BeatmapUpdaterMetadataLookup metadataLookup;
|
||||||
|
|
||||||
|
private const int update_queue_request_concurrency = 4;
|
||||||
|
|
||||||
|
private readonly ThreadedTaskScheduler updateScheduler = new ThreadedTaskScheduler(update_queue_request_concurrency, nameof(BeatmapUpdaterMetadataLookup));
|
||||||
|
|
||||||
public BeatmapUpdater(IWorkingBeatmapCache workingBeatmapCache, BeatmapDifficultyCache difficultyCache, IAPIProvider api, Storage storage)
|
public BeatmapUpdater(IWorkingBeatmapCache workingBeatmapCache, BeatmapDifficultyCache difficultyCache, IAPIProvider api, Storage storage)
|
||||||
{
|
{
|
||||||
this.workingBeatmapCache = workingBeatmapCache;
|
this.workingBeatmapCache = workingBeatmapCache;
|
||||||
this.difficultyCache = difficultyCache;
|
this.difficultyCache = difficultyCache;
|
||||||
|
|
||||||
onlineLookupQueue = new BeatmapOnlineLookupQueue(api, storage);
|
metadataLookup = new BeatmapUpdaterMetadataLookup(api, storage);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -37,7 +44,7 @@ namespace osu.Game.Beatmaps
|
|||||||
public void Queue(Live<BeatmapSetInfo> beatmap)
|
public void Queue(Live<BeatmapSetInfo> beatmap)
|
||||||
{
|
{
|
||||||
Logger.Log($"Queueing change for local beatmap {beatmap}");
|
Logger.Log($"Queueing change for local beatmap {beatmap}");
|
||||||
Task.Factory.StartNew(() => beatmap.PerformRead(Process));
|
Task.Factory.StartNew(() => beatmap.PerformRead(b => Process(b)), default, TaskCreationOptions.HideScheduler | TaskCreationOptions.RunContinuationsAsynchronously, updateScheduler);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -50,7 +57,7 @@ namespace osu.Game.Beatmaps
|
|||||||
|
|
||||||
// TODO: this call currently uses the local `online.db` lookup.
|
// TODO: this call currently uses the local `online.db` lookup.
|
||||||
// We probably don't want this to happen after initial import (as the data may be stale).
|
// We probably don't want this to happen after initial import (as the data may be stale).
|
||||||
onlineLookupQueue.Update(beatmapSet);
|
metadataLookup.Update(beatmapSet);
|
||||||
|
|
||||||
foreach (var beatmap in beatmapSet.Beatmaps)
|
foreach (var beatmap in beatmapSet.Beatmaps)
|
||||||
{
|
{
|
||||||
@ -90,8 +97,11 @@ namespace osu.Game.Beatmaps
|
|||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
if (onlineLookupQueue.IsNotNull())
|
if (metadataLookup.IsNotNull())
|
||||||
onlineLookupQueue.Dispose();
|
metadataLookup.Dispose();
|
||||||
|
|
||||||
|
if (updateScheduler.IsNotNull())
|
||||||
|
updateScheduler.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -6,8 +6,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.Data.Sqlite;
|
using Microsoft.Data.Sqlite;
|
||||||
using osu.Framework.Development;
|
using osu.Framework.Development;
|
||||||
@ -15,7 +13,6 @@ using osu.Framework.IO.Network;
|
|||||||
using osu.Framework.Logging;
|
using osu.Framework.Logging;
|
||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
using osu.Framework.Testing;
|
using osu.Framework.Testing;
|
||||||
using osu.Framework.Threading;
|
|
||||||
using osu.Game.Database;
|
using osu.Game.Database;
|
||||||
using osu.Game.Online.API;
|
using osu.Game.Online.API;
|
||||||
using osu.Game.Online.API.Requests;
|
using osu.Game.Online.API.Requests;
|
||||||
@ -32,20 +29,16 @@ namespace osu.Game.Beatmaps
|
|||||||
/// This will always be checked before doing a second online query to get required metadata.
|
/// This will always be checked before doing a second online query to get required metadata.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
[ExcludeFromDynamicCompile]
|
[ExcludeFromDynamicCompile]
|
||||||
public class BeatmapOnlineLookupQueue : IDisposable
|
public class BeatmapUpdaterMetadataLookup : IDisposable
|
||||||
{
|
{
|
||||||
private readonly IAPIProvider api;
|
private readonly IAPIProvider api;
|
||||||
private readonly Storage storage;
|
private readonly Storage storage;
|
||||||
|
|
||||||
private const int update_queue_request_concurrency = 4;
|
|
||||||
|
|
||||||
private readonly ThreadedTaskScheduler updateScheduler = new ThreadedTaskScheduler(update_queue_request_concurrency, nameof(BeatmapOnlineLookupQueue));
|
|
||||||
|
|
||||||
private FileWebRequest cacheDownloadRequest;
|
private FileWebRequest cacheDownloadRequest;
|
||||||
|
|
||||||
private const string cache_database_name = "online.db";
|
private const string cache_database_name = "online.db";
|
||||||
|
|
||||||
public BeatmapOnlineLookupQueue(IAPIProvider api, Storage storage)
|
public BeatmapUpdaterMetadataLookup(IAPIProvider api, Storage storage)
|
||||||
{
|
{
|
||||||
this.api = api;
|
this.api = api;
|
||||||
this.storage = storage;
|
this.storage = storage;
|
||||||
@ -61,15 +54,6 @@ namespace osu.Game.Beatmaps
|
|||||||
lookup(beatmapSet, b);
|
lookup(beatmapSet, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task UpdateAsync(BeatmapSetInfo beatmapSet, CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
return Task.WhenAll(beatmapSet.Beatmaps.Select(b => UpdateAsync(beatmapSet, b, cancellationToken)).ToArray());
|
|
||||||
}
|
|
||||||
|
|
||||||
// todo: expose this when we need to do individual difficulty lookups.
|
|
||||||
protected Task UpdateAsync(BeatmapSetInfo beatmapSet, BeatmapInfo beatmapInfo, CancellationToken cancellationToken)
|
|
||||||
=> Task.Factory.StartNew(() => lookup(beatmapSet, beatmapInfo), cancellationToken, TaskCreationOptions.HideScheduler | TaskCreationOptions.RunContinuationsAsynchronously, updateScheduler);
|
|
||||||
|
|
||||||
private void lookup(BeatmapSetInfo set, BeatmapInfo beatmapInfo)
|
private void lookup(BeatmapSetInfo set, BeatmapInfo beatmapInfo)
|
||||||
{
|
{
|
||||||
if (checkLocalCache(set, beatmapInfo))
|
if (checkLocalCache(set, beatmapInfo))
|
||||||
@ -134,7 +118,7 @@ namespace osu.Game.Beatmaps
|
|||||||
File.Delete(compressedCacheFilePath);
|
File.Delete(compressedCacheFilePath);
|
||||||
File.Delete(cacheFilePath);
|
File.Delete(cacheFilePath);
|
||||||
|
|
||||||
Logger.Log($"{nameof(BeatmapOnlineLookupQueue)}'s online cache download failed: {ex}", LoggingTarget.Database);
|
Logger.Log($"{nameof(BeatmapUpdaterMetadataLookup)}'s online cache download failed: {ex}", LoggingTarget.Database);
|
||||||
};
|
};
|
||||||
|
|
||||||
cacheDownloadRequest.Finished += () =>
|
cacheDownloadRequest.Finished += () =>
|
||||||
@ -151,7 +135,7 @@ namespace osu.Game.Beatmaps
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Logger.Log($"{nameof(BeatmapOnlineLookupQueue)}'s online cache extraction failed: {ex}", LoggingTarget.Database);
|
Logger.Log($"{nameof(BeatmapUpdaterMetadataLookup)}'s online cache extraction failed: {ex}", LoggingTarget.Database);
|
||||||
File.Delete(cacheFilePath);
|
File.Delete(cacheFilePath);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
@ -238,12 +222,11 @@ namespace osu.Game.Beatmaps
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void logForModel(BeatmapSetInfo set, string message) =>
|
private void logForModel(BeatmapSetInfo set, string message) =>
|
||||||
RealmArchiveModelImporter<BeatmapSetInfo>.LogForModel(set, $"[{nameof(BeatmapOnlineLookupQueue)}] {message}");
|
RealmArchiveModelImporter<BeatmapSetInfo>.LogForModel(set, $"[{nameof(BeatmapUpdaterMetadataLookup)}] {message}");
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
cacheDownloadRequest?.Dispose();
|
cacheDownloadRequest?.Dispose();
|
||||||
updateScheduler?.Dispose();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user