1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 15:07:44 +08:00

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 @@ namespace osu.Game.Beatmaps
AddFile(setInfo, stream, createBeatmapFilenameFromMetadata(beatmapInfo)); 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); Debug.Assert(beatmapInfo.BeatmapSet != null);
beatmapUpdater?.Queue(Realm.Run(r => r.Find<BeatmapSetInfo>(setInfo.ID).ToLive(Realm)));
static string createBeatmapFilenameFromMetadata(BeatmapInfo beatmapInfo) static string createBeatmapFilenameFromMetadata(BeatmapInfo beatmapInfo)
{ {
var metadata = beatmapInfo.Metadata; var metadata = beatmapInfo.Metadata;

View File

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