Centralise calls to reset online info of a `BeatmapInfo`

This commit is contained in:
Dean Herbert 2022-07-25 18:51:19 +09:00
parent ec477a3ebf
commit 6a3e8e31de
6 changed files with 18 additions and 8 deletions

View File

@ -797,7 +797,7 @@ public void TestImportThenDeleteThenImportWithOnlineIDsMissing()
await realm.Realm.WriteAsync(() =>
{
foreach (var b in imported.Beatmaps)
b.OnlineID = -1;
b.ResetOnlineInfo();
});
deleteBeatmapSet(imported, realm.Realm);

View File

@ -239,7 +239,7 @@ public void TestNoSubmissionOnLocalBeatmap()
createPlayerTest(false, r =>
{
var beatmap = createTestBeatmap(r);
beatmap.BeatmapInfo.OnlineID = -1;
beatmap.BeatmapInfo.ResetOnlineInfo();
return beatmap;
});

View File

@ -87,7 +87,7 @@ protected override void PreImport(BeatmapSetInfo beatmapSet, Realm realm)
existingSetWithSameOnlineID.OnlineID = -1;
foreach (var b in existingSetWithSameOnlineID.Beatmaps)
b.OnlineID = -1;
b.ResetOnlineInfo();
LogForModel(beatmapSet, $"Found existing beatmap set with same OnlineID ({beatmapSet.OnlineID}). It will be disassociated and marked for deletion.");
}
@ -133,7 +133,7 @@ private void validateOnlineIds(BeatmapSetInfo beatmapSet, Realm realm)
}
}
void resetIds() => beatmapSet.Beatmaps.ForEach(b => b.OnlineID = -1);
void resetIds() => beatmapSet.Beatmaps.ForEach(b => b.ResetOnlineInfo());
}
protected override bool CanSkipImport(BeatmapSetInfo existing, BeatmapSetInfo import)

View File

@ -109,6 +109,17 @@ public BeatmapOnlineStatus Status
[JsonIgnore]
public bool Hidden { get; set; }
/// <summary>
/// Reset any fetched online linking information (and history).
/// </summary>
public void ResetOnlineInfo()
{
OnlineID = -1;
LastOnlineUpdate = null;
OnlineMD5Hash = string.Empty;
Status = BeatmapOnlineStatus.None;
}
#region Properties we may not want persisted (but also maybe no harm?)
public double AudioLeadIn { get; set; }

View File

@ -164,8 +164,7 @@ public virtual WorkingBeatmap CopyExistingDifficulty(BeatmapSetInfo targetBeatma
// clear the hash, as that's what is used to match .osu files with their corresponding realm beatmaps.
newBeatmapInfo.Hash = string.Empty;
// clear online properties.
newBeatmapInfo.OnlineID = -1;
newBeatmapInfo.Status = BeatmapOnlineStatus.None;
newBeatmapInfo.ResetOnlineInfo();
return addDifficultyToSet(targetBeatmapSet, newBeatmap, referenceWorkingBeatmap.Skin);
}

View File

@ -88,7 +88,7 @@ private void lookup(BeatmapSetInfo set, BeatmapInfo beatmapInfo)
if (req.CompletionState == APIRequestCompletionState.Failed)
{
logForModel(set, $"Online retrieval failed for {beatmapInfo}");
beatmapInfo.OnlineID = -1;
beatmapInfo.ResetOnlineInfo();
return;
}
@ -118,7 +118,7 @@ private void lookup(BeatmapSetInfo set, BeatmapInfo beatmapInfo)
catch (Exception e)
{
logForModel(set, $"Online retrieval failed for {beatmapInfo} ({e.Message})");
beatmapInfo.OnlineID = -1;
beatmapInfo.ResetOnlineInfo();
}
}