Merge branch 'master' into beatmap-update-flow

This commit is contained in:
Dean Herbert
2022-06-30 16:44:17 +09:00
358 changed files with 1056 additions and 958 deletions

View File

@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using osu.Framework.Platform;
@ -46,6 +47,7 @@ namespace osu.Game.Database
Realm.Realm.Write(realm =>
{
var managed = realm.Find<TModel>(item.ID);
Debug.Assert(managed != null);
operation(managed);
item.Files.Clear();

View File

@ -102,6 +102,12 @@ namespace osu.Game.Database
private Realm? updateRealm;
/// <summary>
/// Tracks whether a realm was ever fetched from this instance.
/// After a fetch occurs, blocking operations will be guaranteed to restore any subscriptions.
/// </summary>
private bool hasInitialisedOnce;
private bool isSendingNotificationResetEvents;
public Realm Realm => ensureUpdateRealm();
@ -121,11 +127,12 @@ namespace osu.Game.Database
if (updateRealm == null)
{
updateRealm = getRealmInstance();
hasInitialisedOnce = true;
Logger.Log(@$"Opened realm ""{updateRealm.Config.DatabasePath}"" at version {updateRealm.Config.SchemaVersion}");
// Resubscribe any subscriptions
foreach (var action in customSubscriptionsResetMap.Keys)
foreach (var action in customSubscriptionsResetMap.Keys.ToArray())
registerSubscription(action);
}
@ -454,7 +461,7 @@ namespace osu.Game.Database
public IDisposable SubscribeToPropertyChanged<TModel, TProperty>(Func<Realm, TModel?> modelAccessor, Expression<Func<TModel, TProperty>> propertyLookup, Action<TProperty> onChanged)
where TModel : RealmObjectBase
{
return RegisterCustomSubscription(r =>
return RegisterCustomSubscription(_ =>
{
string propertyName = getMemberName(propertyLookup);
@ -806,13 +813,7 @@ namespace osu.Game.Database
lock (realmLock)
{
if (updateRealm == null)
{
// null realm means the update thread has not yet retrieved its instance.
// we don't need to worry about reviving the update instance in this case, so don't bother with the SynchronizationContext.
Debug.Assert(!ThreadSafety.IsUpdateThread);
}
else
if (hasInitialisedOnce)
{
if (!ThreadSafety.IsUpdateThread)
throw new InvalidOperationException(@$"{nameof(BlockAllOperations)} must be called from the update thread.");
@ -827,12 +828,12 @@ namespace osu.Game.Database
action.Value?.Dispose();
customSubscriptionsResetMap[action.Key] = null;
}
updateRealm?.Dispose();
updateRealm = null;
}
Logger.Log(@"Blocking realm operations.", LoggingTarget.Database);
updateRealm?.Dispose();
updateRealm = null;
}
const int sleep_length = 200;

View File

@ -296,7 +296,8 @@ namespace osu.Game.Database
try
{
LogForModel(item, @"Beginning import...");
// Log output here will be missing a valid hash in non-batch imports.
LogForModel(item, $@"Beginning import from {archive?.Name ?? "unknown"}...");
// TODO: do we want to make the transaction this local? not 100% sure, will need further investigation.
using (var transaction = realm.BeginWrite())

View File

@ -20,7 +20,7 @@ namespace osu.Game.Database
{
private static readonly IMapper write_mapper = new MapperConfiguration(c =>
{
c.ShouldMapField = fi => false;
c.ShouldMapField = _ => false;
c.ShouldMapProperty = pi => pi.SetMethod?.IsPublic == true;
c.CreateMap<BeatmapMetadata, BeatmapMetadata>()
@ -70,7 +70,7 @@ namespace osu.Game.Database
}
});
c.Internal().ForAllMaps((typeMap, expression) =>
c.Internal().ForAllMaps((_, expression) =>
{
expression.ForAllMembers(m =>
{
@ -87,7 +87,7 @@ namespace osu.Game.Database
c.CreateMap<BeatmapSetInfo, BeatmapSetInfo>()
.ConstructUsing(_ => new BeatmapSetInfo(null))
.MaxDepth(2)
.AfterMap((s, d) =>
.AfterMap((_, d) =>
{
foreach (var beatmap in d.Beatmaps)
beatmap.BeatmapSet = d;
@ -97,7 +97,7 @@ namespace osu.Game.Database
// Only hasn't been done yet as we detach at the point of BeatmapInfo less often.
c.CreateMap<BeatmapInfo, BeatmapInfo>()
.MaxDepth(2)
.AfterMap((s, d) =>
.AfterMap((_, d) =>
{
for (int i = 0; i < d.BeatmapSet?.Beatmaps.Count; i++)
{
@ -121,7 +121,7 @@ namespace osu.Game.Database
.ConstructUsing(_ => new BeatmapSetInfo(null))
.MaxDepth(2)
.ForMember(b => b.Files, cc => cc.Ignore())
.AfterMap((s, d) =>
.AfterMap((_, d) =>
{
foreach (var beatmap in d.Beatmaps)
beatmap.BeatmapSet = d;
@ -135,14 +135,14 @@ namespace osu.Game.Database
private static void applyCommonConfiguration(IMapperConfigurationExpression c)
{
c.ShouldMapField = fi => false;
c.ShouldMapField = _ => false;
// This is specifically to avoid mapping explicit interface implementations.
// If we want to limit this further, we can avoid mapping properties with no setter that are not IList<>.
// Takes a bit of effort to determine whether this is the case though, see https://stackoverflow.com/questions/951536/how-do-i-tell-whether-a-type-implements-ilist
c.ShouldMapProperty = pi => pi.GetMethod?.IsPublic == true;
c.Internal().ForAllMaps((typeMap, expression) =>
c.Internal().ForAllMaps((_, expression) =>
{
expression.ForAllMembers(m =>
{