1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-13 04:32:57 +08:00

Update remaining cases of clashing variable name in realm.Run(realm..

This commit is contained in:
Dean Herbert 2022-01-25 13:04:05 +09:00
parent 3e5c9e8436
commit e23b10e6a5
13 changed files with 77 additions and 80 deletions

View File

@ -29,7 +29,7 @@ namespace osu.Game.Benchmarks
realm = new RealmAccess(storage, "client");
realm.Run(realm =>
realm.Run(r =>
{
realm.Write(c => c.Add(TestResources.CreateTestBeatmapSetInfo(rulesets: new[] { new OsuRuleset().RulesetInfo })));
});
@ -41,9 +41,9 @@ namespace osu.Game.Benchmarks
[Benchmark]
public void BenchmarkDirectPropertyRead()
{
realm.Run(realm =>
realm.Run(r =>
{
var beatmapSet = realm.All<BeatmapSetInfo>().First();
var beatmapSet = r.All<BeatmapSetInfo>().First();
for (int i = 0; i < ReadsPerFetch; i++)
{
@ -119,9 +119,9 @@ namespace osu.Game.Benchmarks
[Benchmark]
public void BenchmarkDetachedPropertyRead()
{
realm.Run(realm =>
realm.Run(r =>
{
var beatmapSet = realm.All<BeatmapSetInfo>().First().Detach();
var beatmapSet = r.All<BeatmapSetInfo>().First().Detach();
for (int i = 0; i < ReadsPerFetch; i++)
{

View File

@ -76,9 +76,9 @@ namespace osu.Game.Tests.Database
private int queryCount(GlobalAction? match = null)
{
return realm.Run(realm =>
return realm.Run(r =>
{
var results = realm.All<RealmKeyBinding>();
var results = r.All<RealmKeyBinding>();
if (match.HasValue)
results = results.Where(k => k.ActionInt == (int)match.Value);
return results.Count();

View File

@ -42,11 +42,11 @@ namespace osu.Game.Tests.Visual.Ranking
{
base.LoadComplete();
realm.Run(realm =>
realm.Run(r =>
{
var beatmapInfo = realm.All<BeatmapInfo>()
.Filter($"{nameof(BeatmapInfo.Ruleset)}.{nameof(RulesetInfo.OnlineID)} = $0", 0)
.FirstOrDefault();
var beatmapInfo = r.All<BeatmapInfo>()
.Filter($"{nameof(BeatmapInfo.Ruleset)}.{nameof(RulesetInfo.OnlineID)} = $0", 0)
.FirstOrDefault();
if (beatmapInfo != null)
Beatmap.Value = beatmaps.GetWorkingBeatmap(beatmapInfo);

View File

@ -122,10 +122,10 @@ namespace osu.Game.Tests.Visual.UserInterface
[SetUp]
public void Setup() => Schedule(() =>
{
realm.Run(realm =>
realm.Run(r =>
{
// Due to soft deletions, we can re-use deleted scores between test runs
scoreManager.Undelete(realm.All<ScoreInfo>().Where(s => s.DeletePending).ToList());
scoreManager.Undelete(r.All<ScoreInfo>().Where(s => s.DeletePending).ToList());
});
leaderboard.Scores = null;

View File

@ -119,12 +119,12 @@ namespace osu.Game.Beatmaps
/// <param name="beatmapInfo">The beatmap difficulty to hide.</param>
public void Hide(BeatmapInfo beatmapInfo)
{
realm.Run(realm =>
realm.Run(r =>
{
using (var transaction = realm.BeginWrite())
using (var transaction = r.BeginWrite())
{
if (!beatmapInfo.IsManaged)
beatmapInfo = realm.Find<BeatmapInfo>(beatmapInfo.ID);
beatmapInfo = r.Find<BeatmapInfo>(beatmapInfo.ID);
beatmapInfo.Hidden = true;
transaction.Commit();
@ -138,12 +138,12 @@ namespace osu.Game.Beatmaps
/// <param name="beatmapInfo">The beatmap difficulty to restore.</param>
public void Restore(BeatmapInfo beatmapInfo)
{
realm.Run(realm =>
realm.Run(r =>
{
using (var transaction = realm.BeginWrite())
using (var transaction = r.BeginWrite())
{
if (!beatmapInfo.IsManaged)
beatmapInfo = realm.Find<BeatmapInfo>(beatmapInfo.ID);
beatmapInfo = r.Find<BeatmapInfo>(beatmapInfo.ID);
beatmapInfo.Hidden = false;
transaction.Commit();
@ -153,11 +153,11 @@ namespace osu.Game.Beatmaps
public void RestoreAll()
{
realm.Run(realm =>
realm.Run(r =>
{
using (var transaction = realm.BeginWrite())
using (var transaction = r.BeginWrite())
{
foreach (var beatmap in realm.All<BeatmapInfo>().Where(b => b.Hidden))
foreach (var beatmap in r.All<BeatmapInfo>().Where(b => b.Hidden))
beatmap.Hidden = false;
transaction.Commit();
@ -171,10 +171,10 @@ namespace osu.Game.Beatmaps
/// <returns>A list of available <see cref="BeatmapSetInfo"/>.</returns>
public List<BeatmapSetInfo> GetAllUsableBeatmapSets()
{
return realm.Run(realm =>
return realm.Run(r =>
{
realm.Refresh();
return realm.All<BeatmapSetInfo>().Where(b => !b.DeletePending).Detach();
r.Refresh();
return r.All<BeatmapSetInfo>().Where(b => !b.DeletePending).Detach();
});
}
@ -240,9 +240,9 @@ namespace osu.Game.Beatmaps
public void Delete(Expression<Func<BeatmapSetInfo, bool>>? filter = null, bool silent = false)
{
realm.Run(realm =>
realm.Run(r =>
{
var items = realm.All<BeatmapSetInfo>().Where(s => !s.DeletePending && !s.Protected);
var items = r.All<BeatmapSetInfo>().Where(s => !s.DeletePending && !s.Protected);
if (filter != null)
items = items.Where(filter);
@ -253,7 +253,7 @@ namespace osu.Game.Beatmaps
public void UndeleteAll()
{
realm.Run(realm => beatmapModelManager.Undelete(realm.All<BeatmapSetInfo>().Where(s => s.DeletePending).ToList()));
realm.Run(r => beatmapModelManager.Undelete(r.All<BeatmapSetInfo>().Where(s => s.DeletePending).ToList()));
}
public void Undelete(List<BeatmapSetInfo> items, bool silent = false)
@ -312,9 +312,9 @@ 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(realm =>
realm.Run(r =>
{
var refetch = realm.Find<BeatmapInfo>(importedBeatmap.ID)?.Detach();
var refetch = r.Find<BeatmapInfo>(importedBeatmap.ID)?.Detach();
if (refetch != null)
importedBeatmap = refetch;

View File

@ -158,11 +158,11 @@ namespace osu.Game.Database
int count = existingBeatmapSets.Count();
realm.Run(realm =>
realm.Run(r =>
{
log($"Found {count} beatmaps in EF");
var transaction = realm.BeginWrite();
var transaction = r.BeginWrite();
int written = 0;
try
@ -172,7 +172,7 @@ namespace osu.Game.Database
if (++written % 1000 == 0)
{
transaction.Commit();
transaction = realm.BeginWrite();
transaction = r.BeginWrite();
log($"Migrated {written}/{count} beatmaps...");
}
@ -186,11 +186,11 @@ namespace osu.Game.Database
Protected = beatmapSet.Protected,
};
migrateFiles(beatmapSet, realm, realmBeatmapSet);
migrateFiles(beatmapSet, r, realmBeatmapSet);
foreach (var beatmap in beatmapSet.Beatmaps)
{
var ruleset = realm.Find<RulesetInfo>(beatmap.RulesetInfo.ShortName);
var ruleset = r.Find<RulesetInfo>(beatmap.RulesetInfo.ShortName);
var metadata = getBestMetadata(beatmap.Metadata, beatmapSet.Metadata);
var realmBeatmap = new BeatmapInfo(ruleset, new BeatmapDifficulty(beatmap.BaseDifficulty), metadata)
@ -225,7 +225,7 @@ namespace osu.Game.Database
realmBeatmapSet.Beatmaps.Add(realmBeatmap);
}
realm.Add(realmBeatmapSet);
r.Add(realmBeatmapSet);
}
}
finally
@ -280,11 +280,11 @@ namespace osu.Game.Database
int count = existingScores.Count();
realm.Run(realm =>
realm.Run(r =>
{
log($"Found {count} scores in EF");
var transaction = realm.BeginWrite();
var transaction = r.BeginWrite();
int written = 0;
try
@ -294,12 +294,12 @@ namespace osu.Game.Database
if (++written % 1000 == 0)
{
transaction.Commit();
transaction = realm.BeginWrite();
transaction = r.BeginWrite();
log($"Migrated {written}/{count} scores...");
}
var beatmap = realm.All<BeatmapInfo>().First(b => b.Hash == score.BeatmapInfo.Hash);
var ruleset = realm.Find<RulesetInfo>(score.Ruleset.ShortName);
var beatmap = r.All<BeatmapInfo>().First(b => b.Hash == score.BeatmapInfo.Hash);
var ruleset = r.Find<RulesetInfo>(score.Ruleset.ShortName);
var user = new RealmUser
{
OnlineID = score.User.OnlineID,
@ -329,9 +329,9 @@ namespace osu.Game.Database
APIMods = score.APIMods,
};
migrateFiles(score, realm, realmScore);
migrateFiles(score, r, realmScore);
realm.Add(realmScore);
r.Add(realmScore);
}
}
finally
@ -369,13 +369,13 @@ namespace osu.Game.Database
break;
}
realm.Run(realm =>
realm.Run(r =>
{
using (var transaction = realm.BeginWrite())
using (var transaction = r.BeginWrite())
{
// only migrate data if the realm database is empty.
// note that this cannot be written as: `realm.All<SkinInfo>().All(s => s.Protected)`, because realm does not support `.All()`.
if (!realm.All<SkinInfo>().Any(s => !s.Protected))
// note that this cannot be written as: `r.All<SkinInfo>().All(s => s.Protected)`, because realm does not support `.All()`.
if (!r.All<SkinInfo>().Any(s => !s.Protected))
{
log($"Migrating {existingSkins.Count} skins");
@ -390,9 +390,9 @@ namespace osu.Game.Database
InstantiationInfo = skin.InstantiationInfo,
};
migrateFiles(skin, realm, realmSkin);
migrateFiles(skin, r, realmSkin);
realm.Add(realmSkin);
r.Add(realmSkin);
if (skin.ID == userSkinInt)
userSkinChoice.Value = realmSkin.ID.ToString();
@ -428,12 +428,12 @@ namespace osu.Game.Database
log("Beginning settings migration to realm");
realm.Run(realm =>
realm.Run(r =>
{
using (var transaction = realm.BeginWrite())
using (var transaction = r.BeginWrite())
{
// only migrate data if the realm database is empty.
if (!realm.All<RealmRulesetSetting>().Any())
if (!r.All<RealmRulesetSetting>().Any())
{
log($"Migrating {existingSettings.Count} settings");
@ -447,7 +447,7 @@ namespace osu.Game.Database
if (string.IsNullOrEmpty(shortName))
continue;
realm.Add(new RealmRulesetSetting
r.Add(new RealmRulesetSetting
{
Key = dkb.Key,
Value = dkb.StringValue,

View File

@ -51,10 +51,7 @@ namespace osu.Game.Database
return;
}
realm.Run(realm =>
{
perform(retrieveFromID(realm, ID));
});
realm.Run(r => perform(retrieveFromID(r, ID)));
}
/// <summary>
@ -66,9 +63,9 @@ namespace osu.Game.Database
if (!IsManaged)
return perform(data);
return realm.Run(realm =>
return realm.Run(r =>
{
var returnData = perform(retrieveFromID(realm, ID));
var returnData = perform(retrieveFromID(r, ID));
if (returnData is RealmObjectBase realmObject && realmObject.IsManaged)
throw new InvalidOperationException(@$"Managed realm objects should not exit the scope of {nameof(PerformRead)}.");

View File

@ -56,21 +56,21 @@ namespace osu.Game.Input
/// <param name="rulesets">The rulesets to populate defaults from.</param>
public void Register(KeyBindingContainer container, IEnumerable<RulesetInfo> rulesets)
{
realm.Run(realm =>
realm.Run(r =>
{
using (var transaction = realm.BeginWrite())
using (var transaction = r.BeginWrite())
{
// intentionally flattened to a list rather than querying against the IQueryable, as nullable fields being queried against aren't indexed.
// this is much faster as a result.
var existingBindings = realm.All<RealmKeyBinding>().ToList();
var existingBindings = r.All<RealmKeyBinding>().ToList();
insertDefaults(realm, existingBindings, container.DefaultKeyBindings);
insertDefaults(r, existingBindings, container.DefaultKeyBindings);
foreach (var ruleset in rulesets)
{
var instance = ruleset.CreateInstance();
foreach (int variant in instance.AvailableVariants)
insertDefaults(realm, existingBindings, instance.GetDefaultKeyBindings(variant), ruleset.ShortName, variant);
insertDefaults(r, existingBindings, instance.GetDefaultKeyBindings(variant), ruleset.ShortName, variant);
}
transaction.Commit();

View File

@ -386,10 +386,10 @@ namespace osu.Game.Overlays.Settings.Sections.Input
private void updateStoreFromButton(KeyButton button)
{
realm.Run(realm =>
realm.Run(r =>
{
var binding = realm.Find<RealmKeyBinding>(((IHasGuidPrimaryKey)button.KeyBinding).ID);
realm.Write(() => binding.KeyCombinationString = button.KeyBinding.KeyCombinationString);
var binding = r.Find<RealmKeyBinding>(((IHasGuidPrimaryKey)button.KeyBinding).ID);
r.Write(() => binding.KeyCombinationString = button.KeyBinding.KeyCombinationString);
});
}

View File

@ -51,7 +51,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(realm => realm.All<ScoreInfo>().FirstOrDefault(query)?.Detach());
return realm.Run(r => r.All<ScoreInfo>().FirstOrDefault(query)?.Detach());
}
/// <summary>
@ -254,10 +254,10 @@ namespace osu.Game.Scoring
public void Delete([CanBeNull] Expression<Func<ScoreInfo, bool>> filter = null, bool silent = false)
{
realm.Run(realm =>
realm.Run(r =>
{
var items = realm.All<ScoreInfo>()
.Where(s => !s.DeletePending);
var items = r.All<ScoreInfo>()
.Where(s => !s.DeletePending);
if (filter != null)
items = items.Where(filter);

View File

@ -179,7 +179,7 @@ namespace osu.Game.Screens.Select
if (!loadedTestBeatmaps)
{
realm.Run(realm => loadBeatmapSets(getBeatmapSets(realm)));
realm.Run(r => loadBeatmapSets(getBeatmapSets(r)));
}
}

View File

@ -150,12 +150,12 @@ namespace osu.Game.Screens.Select.Leaderboards
if (Scope == BeatmapLeaderboardScope.Local)
{
realm.Run(realm =>
realm.Run(r =>
{
var scores = realm.All<ScoreInfo>()
.AsEnumerable()
// TODO: update to use a realm filter directly (or at least figure out the beatmap part to reduce scope).
.Where(s => !s.DeletePending && s.BeatmapInfo.ID == fetchBeatmapInfo.ID && s.Ruleset.OnlineID == ruleset.Value.ID);
var scores = r.All<ScoreInfo>()
.AsEnumerable()
// TODO: update to use a realm filter directly (or at least figure out the beatmap part to reduce scope).
.Where(s => !s.DeletePending && s.BeatmapInfo.ID == fetchBeatmapInfo.ID && s.Ruleset.OnlineID == ruleset.Value.ID);
if (filterMods && !mods.Value.Any())
{

View File

@ -289,10 +289,10 @@ namespace osu.Game.Skinning
public void Delete([CanBeNull] Expression<Func<SkinInfo, bool>> filter = null, bool silent = false)
{
realm.Run(realm =>
realm.Run(r =>
{
var items = realm.All<SkinInfo>()
.Where(s => !s.Protected && !s.DeletePending);
var items = r.All<SkinInfo>()
.Where(s => !s.Protected && !s.DeletePending);
if (filter != null)
items = items.Where(filter);