1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-19 13:47:20 +08:00

Merge pull request from peppy/fix-realm-config-save-overhead

Fix changing osu!mania scroll speed causing game-wide lag
This commit is contained in:
Dan Balasescu 2021-10-15 17:33:42 +09:00 committed by GitHub
commit 3d314dad9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -47,9 +47,34 @@ 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();
}
if (realmFactory == null)
return true;
using (var context = realmFactory.CreateContext())
{
context.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 +105,8 @@ namespace osu.Game.Rulesets.Configuration
bindable.ValueChanged += b =>
{
realmFactory?.Context.Write(() => setting.Value = b.NewValue.ToString());
lock (pendingWrites)
pendingWrites.Add(lookup);
};
}
}