1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-08 09:02:57 +08:00

Merge pull request #8494 from peppy/fix-invalid-set-ids-on-import

Fix imports with no matching beatmap IDs still retaining a potentially invalid set ID
This commit is contained in:
Dan Balasescu 2020-03-31 10:42:58 +09:00 committed by GitHub
commit e0a876ceaf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 11 deletions

View File

@ -87,7 +87,7 @@ namespace osu.Game.Beatmaps
protected override bool ShouldDeleteArchive(string path) => Path.GetExtension(path)?.ToLowerInvariant() == ".osz"; protected override bool ShouldDeleteArchive(string path) => Path.GetExtension(path)?.ToLowerInvariant() == ".osz";
protected override Task Populate(BeatmapSetInfo beatmapSet, ArchiveReader archive, CancellationToken cancellationToken = default) protected override async Task Populate(BeatmapSetInfo beatmapSet, ArchiveReader archive, CancellationToken cancellationToken = default)
{ {
if (archive != null) if (archive != null)
beatmapSet.Beatmaps = createBeatmapDifficulties(beatmapSet.Files); beatmapSet.Beatmaps = createBeatmapDifficulties(beatmapSet.Files);
@ -103,7 +103,19 @@ namespace osu.Game.Beatmaps
validateOnlineIds(beatmapSet); validateOnlineIds(beatmapSet);
return updateQueue.UpdateAsync(beatmapSet, cancellationToken); bool hadOnlineBeatmapIDs = beatmapSet.Beatmaps.Any(b => b.OnlineBeatmapID > 0);
await updateQueue.UpdateAsync(beatmapSet, cancellationToken);
// ensure at least one beatmap was able to retrieve or keep an online ID, else drop the set ID.
if (hadOnlineBeatmapIDs && !beatmapSet.Beatmaps.Any(b => b.OnlineBeatmapID > 0))
{
if (beatmapSet.OnlineBeatmapSetID != null)
{
beatmapSet.OnlineBeatmapSetID = null;
LogForModel(beatmapSet, "Disassociating beatmap set ID due to loss of all beatmap IDs");
}
}
} }
protected override void PreImport(BeatmapSetInfo beatmapSet) protected override void PreImport(BeatmapSetInfo beatmapSet)
@ -447,12 +459,15 @@ namespace osu.Game.Beatmaps
var res = req.Result; var res = req.Result;
beatmap.Status = res.Status; if (res != null)
beatmap.BeatmapSet.Status = res.BeatmapSet.Status; {
beatmap.BeatmapSet.OnlineBeatmapSetID = res.OnlineBeatmapSetID; beatmap.Status = res.Status;
beatmap.OnlineBeatmapID = res.OnlineBeatmapID; 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}."); LogForModel(set, $"Online retrieval mapped {beatmap} to {res.OnlineBeatmapSetID} / {res.OnlineBeatmapID}.");
}
} }
catch (Exception e) catch (Exception e)
{ {

View File

@ -12,11 +12,11 @@ namespace osu.Game.Online.API
/// An API request with a well-defined response type. /// An API request with a well-defined response type.
/// </summary> /// </summary>
/// <typeparam name="T">Type of the response (used for deserialisation).</typeparam> /// <typeparam name="T">Type of the response (used for deserialisation).</typeparam>
public abstract class APIRequest<T> : APIRequest public abstract class APIRequest<T> : APIRequest where T : class
{ {
protected override WebRequest CreateWebRequest() => new OsuJsonWebRequest<T>(Uri); protected override WebRequest CreateWebRequest() => new OsuJsonWebRequest<T>(Uri);
public T Result => ((OsuJsonWebRequest<T>)WebRequest).ResponseObject; public T Result => ((OsuJsonWebRequest<T>)WebRequest)?.ResponseObject;
protected APIRequest() protected APIRequest()
{ {

View File

@ -6,7 +6,7 @@ using osu.Game.Rulesets;
namespace osu.Game.Online.API.Requests namespace osu.Game.Online.API.Requests
{ {
public abstract class GetRankingsRequest<TModel> : APIRequest<TModel> public abstract class GetRankingsRequest<TModel> : APIRequest<TModel> where TModel : class
{ {
private readonly RulesetInfo ruleset; private readonly RulesetInfo ruleset;
private readonly int page; private readonly int page;

View File

@ -6,7 +6,7 @@ using osu.Framework.IO.Network;
namespace osu.Game.Online.API.Requests namespace osu.Game.Online.API.Requests
{ {
public abstract class PaginatedAPIRequest<T> : APIRequest<T> public abstract class PaginatedAPIRequest<T> : APIRequest<T> where T : class
{ {
private readonly int page; private readonly int page;
private readonly int itemsPerPage; private readonly int itemsPerPage;