mirror of https://github.com/ppy/osu
Ensure that multiple `BeatmapSetInfo` already in realm don't cause import failures
Really this shouldn't happen but I managed to make it happen. Until this comes up again in a way that matters, let's just fix the LINQ crash from `SingleOrDefault`. I've tested this to work as expected in the broken scenario.
This commit is contained in:
parent
b511c9cc3f
commit
ebe0cfefd8
|
@ -80,9 +80,8 @@ protected override void PreImport(BeatmapSetInfo beatmapSet, Realm realm)
|
||||||
|
|
||||||
if (beatmapSet.OnlineID > 0)
|
if (beatmapSet.OnlineID > 0)
|
||||||
{
|
{
|
||||||
var existingSetWithSameOnlineID = realm.All<BeatmapSetInfo>().SingleOrDefault(b => b.OnlineID == beatmapSet.OnlineID);
|
// OnlineID should really be unique, but to avoid catastrophic failure let's iterate just to be sure.
|
||||||
|
foreach (var existingSetWithSameOnlineID in realm.All<BeatmapSetInfo>().Where(b => b.OnlineID == beatmapSet.OnlineID))
|
||||||
if (existingSetWithSameOnlineID != null)
|
|
||||||
{
|
{
|
||||||
existingSetWithSameOnlineID.DeletePending = true;
|
existingSetWithSameOnlineID.DeletePending = true;
|
||||||
existingSetWithSameOnlineID.OnlineID = -1;
|
existingSetWithSameOnlineID.OnlineID = -1;
|
||||||
|
@ -90,7 +89,7 @@ protected override void PreImport(BeatmapSetInfo beatmapSet, Realm realm)
|
||||||
foreach (var b in existingSetWithSameOnlineID.Beatmaps)
|
foreach (var b in existingSetWithSameOnlineID.Beatmaps)
|
||||||
b.OnlineID = -1;
|
b.OnlineID = -1;
|
||||||
|
|
||||||
LogForModel(beatmapSet, $"Found existing beatmap set with same OnlineID ({beatmapSet.OnlineID}). It will be deleted.");
|
LogForModel(beatmapSet, $"Found existing beatmap set with same OnlineID ({beatmapSet.OnlineID}). It will be disassociated and marked for deletion.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue