mirror of
https://github.com/ppy/osu.git
synced 2025-02-19 23:22:56 +08:00
Fix database unique constraint issues on some imports (#6852)
Fix database unique constraint issues on some imports
This commit is contained in:
commit
20ab8f64c4
@ -129,9 +129,12 @@ namespace osu.Game.Beatmaps
|
|||||||
{
|
{
|
||||||
var beatmapIds = beatmapSet.Beatmaps.Where(b => b.OnlineBeatmapID.HasValue).Select(b => b.OnlineBeatmapID).ToList();
|
var beatmapIds = beatmapSet.Beatmaps.Where(b => b.OnlineBeatmapID.HasValue).Select(b => b.OnlineBeatmapID).ToList();
|
||||||
|
|
||||||
|
LogForModel(beatmapSet, "Validating online IDs...");
|
||||||
|
|
||||||
// ensure all IDs are unique
|
// ensure all IDs are unique
|
||||||
if (beatmapIds.GroupBy(b => b).Any(g => g.Count() > 1))
|
if (beatmapIds.GroupBy(b => b).Any(g => g.Count() > 1))
|
||||||
{
|
{
|
||||||
|
LogForModel(beatmapSet, "Found non-unique IDs, resetting...");
|
||||||
resetIds();
|
resetIds();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -144,9 +147,13 @@ namespace osu.Game.Beatmaps
|
|||||||
// reset the import ids (to force a re-fetch) *unless* they match the candidate CheckForExisting set.
|
// reset the import ids (to force a re-fetch) *unless* they match the candidate CheckForExisting set.
|
||||||
// we can ignore the case where the new ids are contained by the CheckForExisting set as it will either be used (import skipped) or deleted.
|
// we can ignore the case where the new ids are contained by the CheckForExisting set as it will either be used (import skipped) or deleted.
|
||||||
var existing = CheckForExisting(beatmapSet);
|
var existing = CheckForExisting(beatmapSet);
|
||||||
|
|
||||||
if (existing == null || existingBeatmaps.Any(b => !existing.Beatmaps.Contains(b)))
|
if (existing == null || existingBeatmaps.Any(b => !existing.Beatmaps.Contains(b)))
|
||||||
|
{
|
||||||
|
LogForModel(beatmapSet, "Found existing import with IDs already, resetting...");
|
||||||
resetIds();
|
resetIds();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void resetIds() => beatmapSet.Beatmaps.ForEach(b => b.OnlineBeatmapID = null);
|
void resetIds() => beatmapSet.Beatmaps.ForEach(b => b.OnlineBeatmapID = null);
|
||||||
}
|
}
|
||||||
@ -385,25 +392,30 @@ namespace osu.Game.Beatmaps
|
|||||||
|
|
||||||
var req = new GetBeatmapRequest(beatmap);
|
var req = new GetBeatmapRequest(beatmap);
|
||||||
|
|
||||||
req.Success += res =>
|
req.Failure += fail;
|
||||||
{
|
|
||||||
LogForModel(set, $"Online retrieval mapped {beatmap} to {res.OnlineBeatmapSetID} / {res.OnlineBeatmapID}.");
|
|
||||||
|
|
||||||
beatmap.Status = res.Status;
|
|
||||||
beatmap.BeatmapSet.Status = res.BeatmapSet.Status;
|
|
||||||
beatmap.BeatmapSet.OnlineBeatmapSetID = res.OnlineBeatmapSetID;
|
|
||||||
beatmap.OnlineBeatmapID = res.OnlineBeatmapID;
|
|
||||||
};
|
|
||||||
|
|
||||||
req.Failure += e => { LogForModel(set, $"Online retrieval failed for {beatmap} ({e.Message})"); };
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// intentionally blocking to limit web request concurrency
|
// intentionally blocking to limit web request concurrency
|
||||||
req.Perform(api);
|
req.Perform(api);
|
||||||
|
|
||||||
|
var res = req.Result;
|
||||||
|
|
||||||
|
beatmap.Status = res.Status;
|
||||||
|
beatmap.BeatmapSet.Status = res.BeatmapSet.Status;
|
||||||
|
beatmap.BeatmapSet.OnlineBeatmapSetID = res.OnlineBeatmapSetID;
|
||||||
|
beatmap.OnlineBeatmapID = res.OnlineBeatmapID;
|
||||||
|
|
||||||
|
LogForModel(set, $"Online retrieval mapped {beatmap} to {res.OnlineBeatmapSetID} / {res.OnlineBeatmapID}.");
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
fail(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
void fail(Exception e)
|
||||||
|
{
|
||||||
|
beatmap.OnlineBeatmapID = null;
|
||||||
LogForModel(set, $"Online retrieval failed for {beatmap} ({e.Message})");
|
LogForModel(set, $"Online retrieval failed for {beatmap} ({e.Message})");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user