mirror of
https://github.com/ppy/osu.git
synced 2025-01-13 07:22:54 +08:00
Use direct access for query pattern
This commit is contained in:
parent
46a1d99c74
commit
765d9cfae1
@ -6,13 +6,11 @@ using System.Collections.Generic;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Input;
|
|
||||||
using osu.Framework.Input.Bindings;
|
using osu.Framework.Input.Bindings;
|
||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
using osu.Game.Database;
|
using osu.Game.Database;
|
||||||
using osu.Game.Input;
|
using osu.Game.Input;
|
||||||
using osu.Game.Input.Bindings;
|
using osu.Game.Input.Bindings;
|
||||||
using osuTK.Input;
|
|
||||||
|
|
||||||
namespace osu.Game.Tests.Database
|
namespace osu.Game.Tests.Database
|
||||||
{
|
{
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Input.Bindings;
|
using osu.Framework.Input.Bindings;
|
||||||
using osu.Game.Database;
|
using osu.Game.Database;
|
||||||
@ -24,6 +25,9 @@ namespace osu.Game.Input.Bindings
|
|||||||
[Resolved]
|
[Resolved]
|
||||||
private RealmKeyBindingStore store { get; set; }
|
private RealmKeyBindingStore store { get; set; }
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private RealmContextFactory realmFactory { get; set; }
|
||||||
|
|
||||||
public override IEnumerable<IKeyBinding> DefaultKeyBindings => ruleset.CreateInstance().GetDefaultKeyBindings(variant ?? 0);
|
public override IEnumerable<IKeyBinding> DefaultKeyBindings => ruleset.CreateInstance().GetDefaultKeyBindings(variant ?? 0);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -64,7 +68,16 @@ namespace osu.Game.Input.Bindings
|
|||||||
// fallback to defaults instead.
|
// fallback to defaults instead.
|
||||||
KeyBindings = DefaultKeyBindings;
|
KeyBindings = DefaultKeyBindings;
|
||||||
else
|
else
|
||||||
KeyBindings = store.Query(ruleset?.ID, variant).Detach();
|
{
|
||||||
|
var rulesetId = ruleset?.ID;
|
||||||
|
|
||||||
|
// #1
|
||||||
|
KeyBindings = store.Query(rulesetId, variant).Detach();
|
||||||
|
|
||||||
|
// #2 (Clearly shows lifetime of realm context access)
|
||||||
|
using (var realm = realmFactory.Get())
|
||||||
|
KeyBindings = realm.All<RealmKeyBinding>().Where(b => b.RulesetID == rulesetId && b.Variant == variant).Detach();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user