Split updater process into realm transaction and non-transaction

This commit is contained in:
Dean Herbert 2022-06-24 18:27:47 +09:00
parent 021b16f2f3
commit 6999933d33
2 changed files with 28 additions and 24 deletions

View File

@ -319,15 +319,18 @@ public virtual void Save(BeatmapInfo beatmapInfo, IBeatmap beatmapContent, ISkin
AddFile(setInfo, stream, createBeatmapFilenameFromMetadata(beatmapInfo));
Realm.Write(r => setInfo.CopyChangesToRealm(r.Find<BeatmapSetInfo>(setInfo.ID)));
Realm.Write(r =>
{
var liveBeatmapSet = r.Find<BeatmapSetInfo>(setInfo.ID);
setInfo.CopyChangesToRealm(liveBeatmapSet);
beatmapUpdater?.Process(liveBeatmapSet, r);
});
}
workingBeatmapCache.Invalidate(beatmapInfo);
Debug.Assert(beatmapInfo.BeatmapSet != null);
beatmapUpdater?.Queue(Realm.Run(r => r.Find<BeatmapSetInfo>(setInfo.ID).ToLive(Realm)));
static string createBeatmapFilenameFromMetadata(BeatmapInfo beatmapInfo)
{
var metadata = beatmapInfo.Metadata;

View File

@ -8,6 +8,7 @@
using osu.Framework.Extensions;
using osu.Game.Database;
using osu.Game.Rulesets.Objects;
using Realms;
namespace osu.Game.Beatmaps
{
@ -40,10 +41,13 @@ public void Queue(Live<BeatmapSetInfo> beatmap)
/// <summary>
/// Run all processing on a beatmap immediately.
/// </summary>
public void Process(BeatmapSetInfo beatmapSet)
{
beatmapSet.Realm.Write(() =>
public void Process(BeatmapSetInfo beatmapSet) => beatmapSet.Realm.Write(r => Process(beatmapSet, r));
public void Process(BeatmapSetInfo beatmapSet, Realm realm)
{
// Before we use below, we want to invalidate.
workingBeatmapCache.Invalidate(beatmapSet);
onlineLookupQueue.Update(beatmapSet);
foreach (var beatmap in beatmapSet.Beatmaps)
@ -58,9 +62,6 @@ public void Process(BeatmapSetInfo beatmapSet)
beatmap.Length = calculateLength(working.Beatmap);
beatmap.BPM = 60000 / working.Beatmap.GetMostCommonBeatLength();
}
});
workingBeatmapCache.Invalidate(beatmapSet);
}
private double calculateLength(IBeatmap b)