mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 16:27:26 +08:00
Fix realm transactional overhead when rapidly changing RulesetConfigManager
values
This commit is contained in:
parent
d2e5c36780
commit
e47ccbd08a
@ -47,9 +47,28 @@ namespace osu.Game.Rulesets.Configuration
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private readonly HashSet<TLookup> pendingWrites = new HashSet<TLookup>();
|
||||||
|
|
||||||
protected override bool PerformSave()
|
protected override bool PerformSave()
|
||||||
{
|
{
|
||||||
// do nothing, realm saves immediately
|
TLookup[] changed;
|
||||||
|
|
||||||
|
lock (pendingWrites)
|
||||||
|
{
|
||||||
|
changed = pendingWrites.ToArray();
|
||||||
|
pendingWrites.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
realmFactory?.CreateContext().Write(realm =>
|
||||||
|
{
|
||||||
|
foreach (var c in changed)
|
||||||
|
{
|
||||||
|
var setting = realm.All<RealmRulesetSetting>().First(s => s.RulesetID == rulesetId && s.Variant == variant && s.Key == c.ToString());
|
||||||
|
|
||||||
|
setting.Value = ConfigStore[c].ToString();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,7 +99,8 @@ namespace osu.Game.Rulesets.Configuration
|
|||||||
|
|
||||||
bindable.ValueChanged += b =>
|
bindable.ValueChanged += b =>
|
||||||
{
|
{
|
||||||
realmFactory?.Context.Write(() => setting.Value = b.NewValue.ToString());
|
lock (pendingWrites)
|
||||||
|
pendingWrites.Add(lookup);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user