mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 03:03:21 +08:00
Add flow for bypassing local cache lookups when refreshing beatmap metadata
This commit is contained in:
parent
17a3fd30fb
commit
c35da62224
@ -34,7 +34,7 @@ namespace osu.Game.Beatmaps
|
||||
|
||||
protected override string[] HashableFileTypes => new[] { ".osu" };
|
||||
|
||||
public Action<BeatmapSetInfo>? ProcessBeatmap { private get; set; }
|
||||
public Action<BeatmapSetInfo, bool>? ProcessBeatmap { private get; set; }
|
||||
|
||||
public BeatmapImporter(Storage storage, RealmAccess realm)
|
||||
: base(storage, realm)
|
||||
@ -168,11 +168,11 @@ namespace osu.Game.Beatmaps
|
||||
}
|
||||
}
|
||||
|
||||
protected override void PostImport(BeatmapSetInfo model, Realm realm)
|
||||
protected override void PostImport(BeatmapSetInfo model, Realm realm, bool batchImport)
|
||||
{
|
||||
base.PostImport(model, realm);
|
||||
base.PostImport(model, realm, batchImport);
|
||||
|
||||
ProcessBeatmap?.Invoke(model);
|
||||
ProcessBeatmap?.Invoke(model, batchImport);
|
||||
}
|
||||
|
||||
private void validateOnlineIds(BeatmapSetInfo beatmapSet, Realm realm)
|
||||
|
@ -42,7 +42,7 @@ namespace osu.Game.Beatmaps
|
||||
|
||||
private readonly WorkingBeatmapCache workingBeatmapCache;
|
||||
|
||||
public Action<BeatmapSetInfo>? ProcessBeatmap { private get; set; }
|
||||
public Action<BeatmapSetInfo, bool>? ProcessBeatmap { private get; set; }
|
||||
|
||||
public BeatmapManager(Storage storage, RealmAccess realm, RulesetStore rulesets, IAPIProvider? api, AudioManager audioManager, IResourceStore<byte[]> gameResources, GameHost? host = null,
|
||||
WorkingBeatmap? defaultBeatmap = null, BeatmapDifficultyCache? difficultyCache = null, bool performOnlineLookups = false)
|
||||
@ -62,7 +62,7 @@ namespace osu.Game.Beatmaps
|
||||
BeatmapTrackStore = audioManager.GetTrackStore(userResources);
|
||||
|
||||
beatmapImporter = CreateBeatmapImporter(storage, realm);
|
||||
beatmapImporter.ProcessBeatmap = obj => ProcessBeatmap?.Invoke(obj);
|
||||
beatmapImporter.ProcessBeatmap = (obj, isBatch) => ProcessBeatmap?.Invoke(obj, isBatch);
|
||||
beatmapImporter.PostNotification = obj => PostNotification?.Invoke(obj);
|
||||
|
||||
workingBeatmapCache = CreateWorkingBeatmapCache(audioManager, gameResources, userResources, defaultBeatmap, host);
|
||||
@ -323,7 +323,7 @@ namespace osu.Game.Beatmaps
|
||||
|
||||
setInfo.CopyChangesToRealm(liveBeatmapSet);
|
||||
|
||||
ProcessBeatmap?.Invoke(liveBeatmapSet);
|
||||
ProcessBeatmap?.Invoke(liveBeatmapSet, false);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ namespace osu.Game.Beatmaps
|
||||
var matchingSet = r.All<BeatmapSetInfo>().FirstOrDefault(s => s.OnlineID == id);
|
||||
|
||||
if (matchingSet != null)
|
||||
beatmapUpdater.Queue(matchingSet.ToLive(realm));
|
||||
beatmapUpdater.Queue(matchingSet.ToLive(realm), true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -41,23 +41,21 @@ namespace osu.Game.Beatmaps
|
||||
/// <summary>
|
||||
/// Queue a beatmap for background processing.
|
||||
/// </summary>
|
||||
public void Queue(Live<BeatmapSetInfo> beatmap)
|
||||
public void Queue(Live<BeatmapSetInfo> beatmap, bool forceOnlineFetch = false)
|
||||
{
|
||||
Logger.Log($"Queueing change for local beatmap {beatmap}");
|
||||
Task.Factory.StartNew(() => beatmap.PerformRead(b => Process(b)), default, TaskCreationOptions.HideScheduler | TaskCreationOptions.RunContinuationsAsynchronously, updateScheduler);
|
||||
Task.Factory.StartNew(() => beatmap.PerformRead(b => Process(b, forceOnlineFetch)), default, TaskCreationOptions.HideScheduler | TaskCreationOptions.RunContinuationsAsynchronously, updateScheduler);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Run all processing on a beatmap immediately.
|
||||
/// </summary>
|
||||
public void Process(BeatmapSetInfo beatmapSet) => beatmapSet.Realm.Write(r =>
|
||||
public void Process(BeatmapSetInfo beatmapSet, bool forceOnlineFetch = false) => beatmapSet.Realm.Write(r =>
|
||||
{
|
||||
// Before we use below, we want to invalidate.
|
||||
workingBeatmapCache.Invalidate(beatmapSet);
|
||||
|
||||
// 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).
|
||||
metadataLookup.Update(beatmapSet);
|
||||
metadataLookup.Update(beatmapSet, forceOnlineFetch);
|
||||
|
||||
foreach (var beatmap in beatmapSet.Beatmaps)
|
||||
{
|
||||
|
@ -48,15 +48,15 @@ namespace osu.Game.Beatmaps
|
||||
prepareLocalCache();
|
||||
}
|
||||
|
||||
public void Update(BeatmapSetInfo beatmapSet)
|
||||
public void Update(BeatmapSetInfo beatmapSet, bool forceOnlineFetch)
|
||||
{
|
||||
foreach (var b in beatmapSet.Beatmaps)
|
||||
lookup(beatmapSet, b);
|
||||
lookup(beatmapSet, b, forceOnlineFetch);
|
||||
}
|
||||
|
||||
private void lookup(BeatmapSetInfo set, BeatmapInfo beatmapInfo)
|
||||
private void lookup(BeatmapSetInfo set, BeatmapInfo beatmapInfo, bool forceOnlineFetch)
|
||||
{
|
||||
if (checkLocalCache(set, beatmapInfo))
|
||||
if (!forceOnlineFetch && checkLocalCache(set, beatmapInfo))
|
||||
return;
|
||||
|
||||
if (api?.State.Value != APIState.Online)
|
||||
|
@ -340,7 +340,7 @@ namespace osu.Game.Database
|
||||
// import to store
|
||||
realm.Add(item);
|
||||
|
||||
PostImport(item, realm);
|
||||
PostImport(item, realm, batchImport);
|
||||
|
||||
transaction.Commit();
|
||||
}
|
||||
@ -485,7 +485,8 @@ namespace osu.Game.Database
|
||||
/// </summary>
|
||||
/// <param name="model">The model prepared for import.</param>
|
||||
/// <param name="realm">The current realm context.</param>
|
||||
protected virtual void PostImport(TModel model, Realm realm)
|
||||
/// <param name="batchImport">Whether the import was part of a batch.</param>
|
||||
protected virtual void PostImport(TModel model, Realm realm, bool batchImport)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -287,7 +287,7 @@ namespace osu.Game
|
||||
|
||||
AddInternal(new BeatmapOnlineChangeIngest(beatmapUpdater, realm, metadataClient));
|
||||
|
||||
BeatmapManager.ProcessBeatmap = set => beatmapUpdater.Process(set);
|
||||
BeatmapManager.ProcessBeatmap = (set, isBatch) => beatmapUpdater.Process(set, forceOnlineFetch: !isBatch);
|
||||
|
||||
dependencies.Cache(userCache = new UserLookupCache());
|
||||
AddInternal(userCache);
|
||||
|
@ -75,9 +75,9 @@ namespace osu.Game.Scoring
|
||||
model.StatisticsJson = JsonConvert.SerializeObject(model.Statistics);
|
||||
}
|
||||
|
||||
protected override void PostImport(ScoreInfo model, Realm realm)
|
||||
protected override void PostImport(ScoreInfo model, Realm realm, bool batchImport)
|
||||
{
|
||||
base.PostImport(model, realm);
|
||||
base.PostImport(model, realm, batchImport);
|
||||
|
||||
var userRequest = new GetUserRequest(model.RealmUser.Username);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user