Remove local realm fields in manager classes

This commit is contained in:
Dean Herbert 2022-06-16 18:56:53 +09:00
parent f3984d98e6
commit 72c5b9009d
4 changed files with 21 additions and 29 deletions

View File

@ -45,14 +45,10 @@ namespace osu.Game.Beatmaps
private readonly WorkingBeatmapCache workingBeatmapCache;
private readonly BeatmapOnlineLookupQueue? onlineBeatmapLookupQueue;
private readonly RealmAccess realm;
public BeatmapManager(Storage storage, RealmAccess realm, RulesetStore rulesets, IAPIProvider? api, AudioManager audioManager, IResourceStore<byte[]> gameResources, GameHost? host = null,
WorkingBeatmap? defaultBeatmap = null, bool performOnlineLookups = false)
: base(storage, realm)
{
this.realm = realm;
if (performOnlineLookups)
{
if (api == null)
@ -192,7 +188,7 @@ namespace osu.Game.Beatmaps
/// <param name="beatmapInfo">The beatmap difficulty to hide.</param>
public void Hide(BeatmapInfo beatmapInfo)
{
realm.Run(r =>
Realm.Run(r =>
{
using (var transaction = r.BeginWrite())
{
@ -211,7 +207,7 @@ namespace osu.Game.Beatmaps
/// <param name="beatmapInfo">The beatmap difficulty to restore.</param>
public void Restore(BeatmapInfo beatmapInfo)
{
realm.Run(r =>
Realm.Run(r =>
{
using (var transaction = r.BeginWrite())
{
@ -226,7 +222,7 @@ namespace osu.Game.Beatmaps
public void RestoreAll()
{
realm.Run(r =>
Realm.Run(r =>
{
using (var transaction = r.BeginWrite())
{
@ -244,7 +240,7 @@ namespace osu.Game.Beatmaps
/// <returns>A list of available <see cref="BeatmapSetInfo"/>.</returns>
public List<BeatmapSetInfo> GetAllUsableBeatmapSets()
{
return realm.Run(r =>
return Realm.Run(r =>
{
r.Refresh();
return r.All<BeatmapSetInfo>().Where(b => !b.DeletePending).Detach();
@ -258,7 +254,7 @@ namespace osu.Game.Beatmaps
/// <returns>The first result for the provided query, or null if no results were found.</returns>
public Live<BeatmapSetInfo>? QueryBeatmapSet(Expression<Func<BeatmapSetInfo, bool>> query)
{
return realm.Run(r => r.All<BeatmapSetInfo>().FirstOrDefault(query)?.ToLive(realm));
return Realm.Run(r => r.All<BeatmapSetInfo>().FirstOrDefault(query)?.ToLive(Realm));
}
/// <summary>
@ -266,7 +262,7 @@ namespace osu.Game.Beatmaps
/// </summary>
/// <param name="query">The query.</param>
/// <returns>The first result for the provided query, or null if no results were found.</returns>
public BeatmapInfo? QueryBeatmap(Expression<Func<BeatmapInfo, bool>> query) => realm.Run(r => r.All<BeatmapInfo>().FirstOrDefault(query)?.Detach());
public BeatmapInfo? QueryBeatmap(Expression<Func<BeatmapInfo, bool>> query) => Realm.Run(r => r.All<BeatmapInfo>().FirstOrDefault(query)?.Detach());
/// <summary>
/// A default representation of a WorkingBeatmap to use when no beatmap is available.
@ -318,7 +314,7 @@ namespace osu.Game.Beatmaps
AddFile(setInfo, stream, createBeatmapFilenameFromMetadata(beatmapInfo));
realm.Write(r => setInfo.CopyChangesToRealm(r.Find<BeatmapSetInfo>(setInfo.ID)));
Realm.Write(r => setInfo.CopyChangesToRealm(r.Find<BeatmapSetInfo>(setInfo.ID)));
}
workingBeatmapCache.Invalidate(beatmapInfo);
@ -332,7 +328,7 @@ namespace osu.Game.Beatmaps
public void DeleteAllVideos()
{
realm.Write(r =>
Realm.Write(r =>
{
var items = r.All<BeatmapSetInfo>().Where(s => !s.DeletePending && !s.Protected);
DeleteVideos(items.ToList());
@ -341,7 +337,7 @@ namespace osu.Game.Beatmaps
public void Delete(Expression<Func<BeatmapSetInfo, bool>>? filter = null, bool silent = false)
{
realm.Run(r =>
Realm.Run(r =>
{
var items = r.All<BeatmapSetInfo>().Where(s => !s.DeletePending && !s.Protected);
@ -399,7 +395,7 @@ namespace osu.Game.Beatmaps
public void UndeleteAll()
{
realm.Run(r => Undelete(r.All<BeatmapSetInfo>().Where(s => s.DeletePending).ToList()));
Realm.Run(r => Undelete(r.All<BeatmapSetInfo>().Where(s => s.DeletePending).ToList()));
}
#region Implementation of ICanAcceptFiles
@ -431,7 +427,7 @@ namespace osu.Game.Beatmaps
// If we seem to be missing files, now is a good time to re-fetch.
if (importedBeatmap?.BeatmapSet?.Files.Count == 0)
{
realm.Run(r =>
Realm.Run(r =>
{
var refetch = r.Find<BeatmapInfo>(importedBeatmap.ID)?.Detach();

View File

@ -18,7 +18,7 @@ namespace osu.Game.Database
public class ModelManager<TModel> : IModelManager<TModel>, IModelFileManager<TModel, RealmNamedFileUsage>
where TModel : RealmObject, IHasRealmFiles, IHasGuidPrimaryKey, ISoftDelete
{
protected RealmAccess Realm;
protected RealmAccess Realm { get; }
private readonly RealmFileStore realmFileStore;

View File

@ -24,7 +24,6 @@ namespace osu.Game.Scoring
{
public class ScoreManager : ModelManager<ScoreInfo>, IModelImporter<ScoreInfo>
{
private readonly RealmAccess realm;
private readonly Scheduler scheduler;
private readonly Func<BeatmapDifficultyCache> difficulties;
private readonly OsuConfigManager configManager;
@ -34,7 +33,6 @@ namespace osu.Game.Scoring
Func<BeatmapDifficultyCache> difficulties = null, OsuConfigManager configManager = null)
: base(storage, realm)
{
this.realm = realm;
this.scheduler = scheduler;
this.difficulties = difficulties;
this.configManager = configManager;
@ -51,7 +49,7 @@ namespace osu.Game.Scoring
/// <returns>The first result for the provided query, or null if no results were found.</returns>
public ScoreInfo Query(Expression<Func<ScoreInfo, bool>> query)
{
return realm.Run(r => r.All<ScoreInfo>().FirstOrDefault(query)?.Detach());
return Realm.Run(r => r.All<ScoreInfo>().FirstOrDefault(query)?.Detach());
}
/// <summary>
@ -230,7 +228,7 @@ namespace osu.Game.Scoring
public void Delete([CanBeNull] Expression<Func<ScoreInfo, bool>> filter = null, bool silent = false)
{
realm.Run(r =>
Realm.Run(r =>
{
var items = r.All<ScoreInfo>()
.Where(s => !s.DeletePending);
@ -244,7 +242,7 @@ namespace osu.Game.Scoring
public void Delete(BeatmapInfo beatmap, bool silent = false)
{
realm.Run(r =>
Realm.Run(r =>
{
var beatmapScores = r.Find<BeatmapInfo>(beatmap.ID).Scores.ToList();
Delete(beatmapScores, silent);

View File

@ -54,7 +54,6 @@ namespace osu.Game.Skinning
};
private readonly SkinImporter skinImporter;
private readonly RealmAccess realm;
private readonly IResourceStore<byte[]> userFiles;
@ -71,7 +70,6 @@ namespace osu.Game.Skinning
public SkinManager(Storage storage, RealmAccess realm, GameHost host, IResourceStore<byte[]> resources, AudioManager audio, Scheduler scheduler)
: base(storage, realm)
{
this.realm = realm;
this.audio = audio;
this.scheduler = scheduler;
this.host = host;
@ -114,7 +112,7 @@ namespace osu.Game.Skinning
public void SelectRandomSkin()
{
realm.Run(r =>
Realm.Run(r =>
{
// choose from only user skins, removing the current selection to ensure a new one is chosen.
var randomChoices = r.All<SkinInfo>().Where(s => !s.DeletePending && s.ID != CurrentSkinInfo.Value.ID).ToArray();
@ -127,7 +125,7 @@ namespace osu.Game.Skinning
var chosen = randomChoices.ElementAt(RNG.Next(0, randomChoices.Length));
CurrentSkinInfo.Value = chosen.ToLive(realm);
CurrentSkinInfo.Value = chosen.ToLive(Realm);
});
}
@ -152,7 +150,7 @@ namespace osu.Game.Skinning
if (!s.Protected)
return false;
string[] existingSkinNames = realm.Run(r => r.All<SkinInfo>()
string[] existingSkinNames = Realm.Run(r => r.All<SkinInfo>()
.Where(skin => !skin.DeletePending)
.AsEnumerable()
.Select(skin => skin.Name).ToArray());
@ -195,7 +193,7 @@ namespace osu.Game.Skinning
/// <returns>The first result for the provided query, or null if no results were found.</returns>
public Live<SkinInfo> Query(Expression<Func<SkinInfo, bool>> query)
{
return realm.Run(r => r.All<SkinInfo>().FirstOrDefault(query)?.ToLive(realm));
return Realm.Run(r => r.All<SkinInfo>().FirstOrDefault(query)?.ToLive(Realm));
}
public event Action SourceChanged;
@ -250,7 +248,7 @@ namespace osu.Game.Skinning
AudioManager IStorageResourceProvider.AudioManager => audio;
IResourceStore<byte[]> IStorageResourceProvider.Resources => resources;
IResourceStore<byte[]> IStorageResourceProvider.Files => userFiles;
RealmAccess IStorageResourceProvider.RealmAccess => realm;
RealmAccess IStorageResourceProvider.RealmAccess => Realm;
IResourceStore<TextureUpload> IStorageResourceProvider.CreateTextureLoaderStore(IResourceStore<byte[]> underlyingStore) => host.CreateTextureLoaderStore(underlyingStore);
#endregion
@ -279,7 +277,7 @@ namespace osu.Game.Skinning
public void Delete([CanBeNull] Expression<Func<SkinInfo, bool>> filter = null, bool silent = false)
{
realm.Run(r =>
Realm.Run(r =>
{
var items = r.All<SkinInfo>()
.Where(s => !s.Protected && !s.DeletePending);