1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 06:57:39 +08:00

Ensure scores are cleaned up alongside beatmap so they don't have a null reference

This commit is contained in:
Dean Herbert 2022-01-12 15:09:56 +09:00
parent f24b2b1be3
commit 5f7365e8f3
2 changed files with 15 additions and 4 deletions

View File

@ -11,6 +11,7 @@ using osu.Game.Database;
using osu.Game.Models;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Rulesets;
using osu.Game.Scoring;
using Realms;
#nullable enable
@ -36,6 +37,10 @@ namespace osu.Game.Beatmaps
public BeatmapMetadata Metadata { get; set; } = new BeatmapMetadata();
[IgnoreMap]
[Backlink(nameof(ScoreInfo.Beatmap))]
public IQueryable<ScoreInfo> Scores { get; } = null!;
public BeatmapInfo(RulesetInfo ruleset, BeatmapDifficulty difficulty, BeatmapMetadata metadata)
{
Ruleset = ruleset;

View File

@ -113,12 +113,18 @@ namespace osu.Game.Database
{
var pendingDeleteSets = realm.All<BeatmapSetInfo>().Where(s => s.DeletePending);
foreach (var s in pendingDeleteSets)
foreach (var beatmapSet in pendingDeleteSets)
{
foreach (var b in s.Beatmaps)
realm.Remove(b);
foreach (var beatmap in beatmapSet.Beatmaps)
{
// Cascade delete related scores, else they will have a null beatmap against the model's spec.
foreach (var score in beatmap.Scores)
realm.Remove(score);
realm.Remove(s);
realm.Remove(beatmap);
}
realm.Remove(beatmapSet);
}
var pendingDeleteSkins = realm.All<SkinInfo>().Where(s => s.DeletePending);