1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 10:33:30 +08:00

Add button to compact realm on demand

In general we're doing things correctly so the realm file shouldn't
expand (unless mass deletions are made from it), but this is a nice way
to manually confirm the behaviour.

Sometimes if using realm studio with osu! running, for instance, the
realm file size can blow out of proportion. This will recover from such
cases.

Note that calling `RealmFactory.Compact` itself is not enough, as it
will fail unless all instances of the realm have been closed.
This commit is contained in:
Dean Herbert 2022-01-12 15:20:48 +09:00
parent 06a5b89071
commit 11e07c1137
2 changed files with 18 additions and 1 deletions

View File

@ -44,6 +44,11 @@ namespace osu.Game.Localisation
/// </summary>
public static LocalisableString ClearAllCaches => new TranslatableString(getKey(@"clear_all_caches"), @"Clear all caches");
/// <summary>
/// "Compact realm"
/// </summary>
public static LocalisableString CompactRealm => new TranslatableString(getKey(@"compact_realm"), @"Compact realm");
private static string getKey(string key) => $"{prefix}:{key}";
}
}

View File

@ -6,6 +6,7 @@ using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Localisation;
using osu.Framework.Platform;
using osu.Game.Database;
using osu.Game.Localisation;
namespace osu.Game.Overlays.Settings.Sections.DebugSettings
@ -15,7 +16,7 @@ namespace osu.Game.Overlays.Settings.Sections.DebugSettings
protected override LocalisableString Header => DebugSettingsStrings.MemoryHeader;
[BackgroundDependencyLoader]
private void load(FrameworkDebugConfigManager config, GameHost host)
private void load(FrameworkDebugConfigManager config, GameHost host, RealmContextFactory realmFactory)
{
Children = new Drawable[]
{
@ -24,6 +25,17 @@ namespace osu.Game.Overlays.Settings.Sections.DebugSettings
Text = DebugSettingsStrings.ClearAllCaches,
Action = host.Collect
},
new SettingsButton
{
Text = DebugSettingsStrings.CompactRealm,
Action = () =>
{
// Blocking operations implicitly causes a Compact().
using (realmFactory.BlockAllOperations())
{
}
}
},
};
}
}