Add OriginalBeatmapHash to ScoreInfo. Update db schema_version, migration

This commit is contained in:
Cootz 2023-02-05 21:46:38 +03:00
parent b792dc3af0
commit 4598112586
3 changed files with 25 additions and 0 deletions

View File

@ -13,6 +13,7 @@
using osu.Framework.Audio;
using osu.Framework.Audio.Track;
using osu.Framework.Extensions;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.IO.Stores;
using osu.Framework.Platform;
using osu.Framework.Testing;
@ -25,6 +26,7 @@
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays.Notifications;
using osu.Game.Rulesets;
using osu.Game.Scoring;
using osu.Game.Skinning;
using osu.Game.Utils;
@ -454,6 +456,12 @@ private void save(BeatmapInfo beatmapInfo, IBeatmap beatmapContent, ISkin? beatm
if (transferCollections)
beatmapInfo.TransferCollectionReferences(r, oldMd5Hash);
//Unlinking all scores from this beatmap
r.All<ScoreInfo>().Where(s => s.BeatmapInfoID == beatmapInfo.ID).ForEach(s => s.BeatmapInfo = new BeatmapInfo());
//Linking all the previos scores
r.All<ScoreInfo>().Where(s => s.OriginalBeatmapHash == beatmapInfo.Hash).ForEach(s => s.BeatmapInfo = beatmapInfo);
ProcessBeatmap?.Invoke((liveBeatmapSet, false));
});
}

View File

@ -70,6 +70,7 @@ public class RealmAccess : IDisposable
/// 23 2022-08-01 Added LastLocalUpdate to BeatmapInfo.
/// 24 2022-08-22 Added MaximumStatistics to ScoreInfo.
/// 25 2022-09-18 Remove skins to add with new naming.
/// 26 2023-02-05 Added OriginalBeatmapHash to ScoreInfo.
/// </summary>
private const int schema_version = 25;
@ -865,6 +866,20 @@ void convertOnlineIDs<T>() where T : RealmObject
case 25:
// Remove the default skins so they can be added back by SkinManager with updated naming.
migration.NewRealm.RemoveRange(migration.NewRealm.All<SkinInfo>().Where(s => s.Protected));
break;
case 26:
// Adding origin beatmap hash property to ensure the score corresponds to the version of beatmap it should
// See: https://github.com/ppy/osu/issues/22062
string ScoreInfoName = getMappedOrOriginalName(typeof(ScoreInfo));
var oldScoreInfos = migration.OldRealm.DynamicApi.All(ScoreInfoName);
var newScoreInfos = migration.NewRealm.All<ScoreInfo>();
for (int i = 0; i < newScoreInfos.Count(); i++)
{
newScoreInfos.ElementAt(i).OriginalBeatmapHash = oldScoreInfos.ElementAt(i).BeatmapInfo.Hash;
}
break;
}
}

View File

@ -66,6 +66,8 @@ public class ScoreInfo : RealmObject, IHasGuidPrimaryKey, IHasRealmFiles, ISoftD
[MapTo("MaximumStatistics")]
public string MaximumStatisticsJson { get; set; } = string.Empty;
public string OriginalBeatmapHash { get; set; } = string.Empty;
public ScoreInfo(BeatmapInfo? beatmap = null, RulesetInfo? ruleset = null, RealmUser? realmUser = null)
{
Ruleset = ruleset ?? new RulesetInfo();