1
0
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:
Dean Herbert 2021-01-12 17:01:40 +09:00
parent 46a1d99c74
commit 765d9cfae1
2 changed files with 14 additions and 3 deletions

View File

@ -6,13 +6,11 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Input;
using osu.Framework.Input.Bindings;
using osu.Framework.Platform;
using osu.Game.Database;
using osu.Game.Input;
using osu.Game.Input.Bindings;
using osuTK.Input;
namespace osu.Game.Tests.Database
{

View File

@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Input.Bindings;
using osu.Game.Database;
@ -24,6 +25,9 @@ namespace osu.Game.Input.Bindings
[Resolved]
private RealmKeyBindingStore store { get; set; }
[Resolved]
private RealmContextFactory realmFactory { get; set; }
public override IEnumerable<IKeyBinding> DefaultKeyBindings => ruleset.CreateInstance().GetDefaultKeyBindings(variant ?? 0);
/// <summary>
@ -64,7 +68,16 @@ namespace osu.Game.Input.Bindings
// fallback to defaults instead.
KeyBindings = DefaultKeyBindings;
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();
}
}
}
}