mirror of
https://github.com/osukey/osukey.git
synced 2025-06-05 12:57:39 +09:00
Rename parameter to read better (and still use local cache if no online API is available)
This commit is contained in:
parent
c35da62224
commit
8cb4fb35e0
@ -41,21 +41,25 @@ namespace osu.Game.Beatmaps
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Queue a beatmap for background processing.
|
/// Queue a beatmap for background processing.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Queue(Live<BeatmapSetInfo> beatmap, bool forceOnlineFetch = false)
|
/// <param name="beatmapSet">The managed beatmap set to update. A transaction will be opened to apply changes.</param>
|
||||||
|
/// <param name="preferOnlineFetch">Whether metadata from an online source should be preferred. If <c>true</c>, the local cache will be skipped to ensure the freshest data state possible.</param>
|
||||||
|
public void Queue(Live<BeatmapSetInfo> beatmapSet, bool preferOnlineFetch = false)
|
||||||
{
|
{
|
||||||
Logger.Log($"Queueing change for local beatmap {beatmap}");
|
Logger.Log($"Queueing change for local beatmap {beatmapSet}");
|
||||||
Task.Factory.StartNew(() => beatmap.PerformRead(b => Process(b, forceOnlineFetch)), default, TaskCreationOptions.HideScheduler | TaskCreationOptions.RunContinuationsAsynchronously, updateScheduler);
|
Task.Factory.StartNew(() => beatmapSet.PerformRead(b => Process(b, preferOnlineFetch)), default, TaskCreationOptions.HideScheduler | TaskCreationOptions.RunContinuationsAsynchronously, updateScheduler);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Run all processing on a beatmap immediately.
|
/// Run all processing on a beatmap immediately.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Process(BeatmapSetInfo beatmapSet, bool forceOnlineFetch = false) => beatmapSet.Realm.Write(r =>
|
/// <param name="beatmapSet">The managed beatmap set to update. A transaction will be opened to apply changes.</param>
|
||||||
|
/// <param name="preferOnlineFetch">Whether metadata from an online source should be preferred. If <c>true</c>, the local cache will be skipped to ensure the freshest data state possible.</param>
|
||||||
|
public void Process(BeatmapSetInfo beatmapSet, bool preferOnlineFetch = false) => beatmapSet.Realm.Write(r =>
|
||||||
{
|
{
|
||||||
// Before we use below, we want to invalidate.
|
// Before we use below, we want to invalidate.
|
||||||
workingBeatmapCache.Invalidate(beatmapSet);
|
workingBeatmapCache.Invalidate(beatmapSet);
|
||||||
|
|
||||||
metadataLookup.Update(beatmapSet, forceOnlineFetch);
|
metadataLookup.Update(beatmapSet, preferOnlineFetch);
|
||||||
|
|
||||||
foreach (var beatmap in beatmapSet.Beatmaps)
|
foreach (var beatmap in beatmapSet.Beatmaps)
|
||||||
{
|
{
|
||||||
|
@ -48,18 +48,27 @@ namespace osu.Game.Beatmaps
|
|||||||
prepareLocalCache();
|
prepareLocalCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Update(BeatmapSetInfo beatmapSet, bool forceOnlineFetch)
|
/// <summary>
|
||||||
|
/// Queue an update for a beatmap set.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="beatmapSet">The beatmap set to update. Updates will be applied directly (so a transaction should be started if this instance is managed).</param>
|
||||||
|
/// <param name="preferOnlineFetch">Whether metadata from an online source should be preferred. If <c>true</c>, the local cache will be skipped to ensure the freshest data state possible.</param>
|
||||||
|
public void Update(BeatmapSetInfo beatmapSet, bool preferOnlineFetch)
|
||||||
{
|
{
|
||||||
foreach (var b in beatmapSet.Beatmaps)
|
foreach (var b in beatmapSet.Beatmaps)
|
||||||
lookup(beatmapSet, b, forceOnlineFetch);
|
lookup(beatmapSet, b, preferOnlineFetch);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void lookup(BeatmapSetInfo set, BeatmapInfo beatmapInfo, bool forceOnlineFetch)
|
private void lookup(BeatmapSetInfo set, BeatmapInfo beatmapInfo, bool preferOnlineFetch)
|
||||||
{
|
{
|
||||||
if (!forceOnlineFetch && checkLocalCache(set, beatmapInfo))
|
bool apiAvailable = api?.State.Value == APIState.Online;
|
||||||
|
|
||||||
|
bool useLocalCache = !apiAvailable || !preferOnlineFetch;
|
||||||
|
|
||||||
|
if (useLocalCache && checkLocalCache(set, beatmapInfo))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (api?.State.Value != APIState.Online)
|
if (!apiAvailable)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var req = new GetBeatmapRequest(beatmapInfo);
|
var req = new GetBeatmapRequest(beatmapInfo);
|
||||||
|
@ -287,7 +287,7 @@ namespace osu.Game
|
|||||||
|
|
||||||
AddInternal(new BeatmapOnlineChangeIngest(beatmapUpdater, realm, metadataClient));
|
AddInternal(new BeatmapOnlineChangeIngest(beatmapUpdater, realm, metadataClient));
|
||||||
|
|
||||||
BeatmapManager.ProcessBeatmap = (set, isBatch) => beatmapUpdater.Process(set, forceOnlineFetch: !isBatch);
|
BeatmapManager.ProcessBeatmap = (set, isBatch) => beatmapUpdater.Process(set, preferOnlineFetch: !isBatch);
|
||||||
|
|
||||||
dependencies.Cache(userCache = new UserLookupCache());
|
dependencies.Cache(userCache = new UserLookupCache());
|
||||||
AddInternal(userCache);
|
AddInternal(userCache);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user