Fix various cases of creating realm contexts from update thread when not necessary

This commit is contained in:
Dean Herbert
2022-01-21 01:34:20 +09:00
parent 0c9eb3ad61
commit a5d2047f05
7 changed files with 36 additions and 37 deletions

View File

@ -98,17 +98,16 @@ namespace osu.Game.Beatmaps
/// <returns>The first result for the provided query, or null if no results were found.</returns>
public BeatmapInfo? QueryBeatmap(Expression<Func<BeatmapInfo, bool>> query)
{
using (var context = ContextFactory.CreateContext())
return context.All<BeatmapInfo>().FirstOrDefault(query)?.Detach();
return ContextFactory.Run(realm => realm.All<BeatmapInfo>().FirstOrDefault(query)?.Detach());
}
public void Update(BeatmapSetInfo item)
{
using (var realm = ContextFactory.CreateContext())
ContextFactory.Run(realm =>
{
var existing = realm.Find<BeatmapSetInfo>(item.ID);
realm.Write(r => item.CopyChangesToRealm(existing));
}
});
}
}
}