1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 03:27:24 +08:00

Fix realm transactional overhead when rapidly changing RulesetConfigManager values

This commit is contained in:
Dean Herbert 2021-10-15 13:50:25 +09:00
parent d2e5c36780
commit e47ccbd08a

View File

@ -47,9 +47,28 @@ namespace osu.Game.Rulesets.Configuration
}
}
private readonly HashSet<TLookup> pendingWrites = new HashSet<TLookup>();
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;
}
@ -80,7 +99,8 @@ namespace osu.Game.Rulesets.Configuration
bindable.ValueChanged += b =>
{
realmFactory?.Context.Write(() => setting.Value = b.NewValue.ToString());
lock (pendingWrites)
pendingWrites.Add(lookup);
};
}
}