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

Add migration

This commit is contained in:
Dean Herbert 2024-01-22 20:55:17 +09:00
parent 4eba3b5d70
commit 644e7d6fe6
No known key found for this signature in database
2 changed files with 60 additions and 1 deletions

View File

@ -73,6 +73,7 @@ namespace osu.Game.Database
processBeatmapsWithMissingObjectCounts();
processScoresWithMissingStatistics();
convertLegacyTotalScoreToStandardised();
upgradeScoreRanks();
}, TaskCreationOptions.LongRunning).ContinueWith(t =>
{
if (t.Exception?.InnerException is ObjectDisposedException)
@ -354,6 +355,7 @@ namespace osu.Game.Database
realmAccess.Write(r =>
{
ScoreInfo s = r.Find<ScoreInfo>(id)!;
// TODO: ensure that this is also updating rank (as it will set TotalScoreVersion to latest).
StandardisedScoreMigrationTools.UpdateFromLegacy(s, beatmapManager);
s.TotalScoreVersion = LegacyScoreEncoder.LATEST_VERSION;
});
@ -375,6 +377,62 @@ namespace osu.Game.Database
completeNotification(notification, processedCount, scoreIds.Count, failedCount);
}
private void upgradeScoreRanks()
{
Logger.Log("Querying for scores that need rank upgrades...");
HashSet<Guid> scoreIds = realmAccess.Run(r => new HashSet<Guid>(
r.All<ScoreInfo>()
.Where(s => s.TotalScoreVersion < LegacyScoreEncoder.LATEST_VERSION)
.Select(s => s.ID)));
Logger.Log($"Found {scoreIds.Count} scores which require rank upgrades.");
if (scoreIds.Count == 0)
return;
var notification = showProgressNotification(scoreIds.Count, "Adjusting ranks of scores", "scores now have more correct ranks");
int processedCount = 0;
int failedCount = 0;
foreach (var id in scoreIds)
{
if (notification?.State == ProgressNotificationState.Cancelled)
break;
updateNotificationProgress(notification, processedCount, scoreIds.Count);
sleepIfRequired();
try
{
// Can't use async overload because we're not on the update thread.
// ReSharper disable once MethodHasAsyncOverload
realmAccess.Write(r =>
{
ScoreInfo s = r.Find<ScoreInfo>(id)!;
// TODO: uncomment when ready
// s.Rank = StandardisedScoreMigrationTools.ComputeRank(s, beatmapManager);
});
++processedCount;
}
catch (ObjectDisposedException)
{
throw;
}
catch (Exception e)
{
Logger.Log($"Failed to update rank score {id}: {e}");
realmAccess.Write(r => r.Find<ScoreInfo>(id)!.BackgroundReprocessingFailed = true);
++failedCount;
}
}
completeNotification(notification, processedCount, scoreIds.Count, failedCount);
}
private void updateNotificationProgress(ProgressNotification? notification, int processedCount, int totalCount)
{
if (notification == null)

View File

@ -43,9 +43,10 @@ namespace osu.Game.Scoring.Legacy
/// 30000012: Fix incorrect total score conversion on selected beatmaps after implementing the more correct
/// <see cref="LegacyRulesetExtensions.CalculateDifficultyPeppyStars"/> method. Reconvert all scores.
/// </description></item>
/// <item><description>30000013: All local scores will use lazer definitions of ranks for consistency. Recalculates the rank of all scores.</description></item>
/// </list>
/// </remarks>
public const int LATEST_VERSION = 30000012;
public const int LATEST_VERSION = 30000013;
/// <summary>
/// The first stable-compatible YYYYMMDD format version given to lazer usage of replays.