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,27 +41,27 @@ public void Queue(Live<BeatmapSetInfo> beatmap)
/// <summary>
/// Run all processing on a beatmap immediately.
/// </summary>
public void Process(BeatmapSetInfo beatmapSet)
public void Process(BeatmapSetInfo beatmapSet) => beatmapSet.Realm.Write(r => Process(beatmapSet, r));
public void Process(BeatmapSetInfo beatmapSet, Realm realm)
{
beatmapSet.Realm.Write(() =>
{
onlineLookupQueue.Update(beatmapSet);
foreach (var beatmap in beatmapSet.Beatmaps)
{
// Because we aren't guaranteed all processing will happen on this thread, it's very hard to use the live realm object.
// This can be fixed by adding a synchronous flow to `BeatmapDifficultyCache`.
var detachedBeatmap = beatmap.Detach();
beatmap.StarRating = difficultyCache.GetDifficultyAsync(detachedBeatmap).GetResultSafely()?.Stars ?? 0;
var working = workingBeatmapCache.GetWorkingBeatmap(beatmap);
beatmap.Length = calculateLength(working.Beatmap);
beatmap.BPM = 60000 / working.Beatmap.GetMostCommonBeatLength();
}
});
// Before we use below, we want to invalidate.
workingBeatmapCache.Invalidate(beatmapSet);
onlineLookupQueue.Update(beatmapSet);
foreach (var beatmap in beatmapSet.Beatmaps)
{
// Because we aren't guaranteed all processing will happen on this thread, it's very hard to use the live realm object.
// This can be fixed by adding a synchronous flow to `BeatmapDifficultyCache`.
var detachedBeatmap = beatmap.Detach();
beatmap.StarRating = difficultyCache.GetDifficultyAsync(detachedBeatmap).GetResultSafely()?.Stars ?? 0;
var working = workingBeatmapCache.GetWorkingBeatmap(beatmap);
beatmap.Length = calculateLength(working.Beatmap);
beatmap.BPM = 60000 / working.Beatmap.GetMostCommonBeatLength();
}
}
private double calculateLength(IBeatmap b)