Add transaction usage for key binding defaults

This commit is contained in:
Dean Herbert 2017-10-22 16:17:55 +09:00
parent 29fcd210aa
commit 9aa46bfb0d

View File

@ -36,29 +36,31 @@ namespace osu.Game.Input
private void insertDefaults(IEnumerable<KeyBinding> defaults, int? rulesetId = null, int? variant = null)
{
var context = GetContext();
// compare counts in database vs defaults
foreach (var group in defaults.GroupBy(k => k.Action))
using (var context = GetContext())
using (var transaction = context.Database.BeginTransaction())
{
int count = query(context, rulesetId, variant).Count(k => (int)k.Action == (int)group.Key);
int aimCount = group.Count();
// compare counts in database vs defaults
foreach (var group in defaults.GroupBy(k => k.Action))
{
int count = query(context, rulesetId, variant).Count(k => (int)k.Action == (int)group.Key);
int aimCount = group.Count();
if (aimCount <= count)
continue;
if (aimCount <= count)
continue;
foreach (var insertable in group.Skip(count).Take(aimCount - count))
// insert any defaults which are missing.
context.DatabasedKeyBinding.Add(new DatabasedKeyBinding
{
KeyCombination = insertable.KeyCombination,
Action = insertable.Action,
RulesetID = rulesetId,
Variant = variant
});
foreach (var insertable in group.Skip(count).Take(aimCount - count))
// insert any defaults which are missing.
context.DatabasedKeyBinding.Add(new DatabasedKeyBinding
{
KeyCombination = insertable.KeyCombination,
Action = insertable.Action,
RulesetID = rulesetId,
Variant = variant
});
}
context.SaveChanges(transaction);
}
context.SaveChanges();
}
/// <summary>