Skip to content

Commit

Permalink
Add migration
Browse files Browse the repository at this point in the history
  • Loading branch information
peppy committed Jan 22, 2024
1 parent 0a8f58a commit 5d90151
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
57 changes: 57 additions & 0 deletions osu.Game/Database/BackgroundDataStoreProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ protected override void LoadComplete()
processBeatmapsWithMissingObjectCounts();
processScoresWithMissingStatistics();
convertLegacyTotalScoreToStandardised();
upgradeScoreRanks();
}, TaskCreationOptions.LongRunning).ContinueWith(t =>
{
if (t.Exception?.InnerException is ObjectDisposedException)
Expand Down Expand Up @@ -354,6 +355,7 @@ private void convertLegacyTotalScoreToStandardised()
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;
});
Expand All @@ -375,6 +377,61 @@ private void convertLegacyTotalScoreToStandardised()
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)!;
s.Rank = StandardisedScoreMigrationTools.ComputeRank(s, beatmapManager);

Check failure on line 415 in osu.Game/Database/BackgroundDataStoreProcessor.cs

View workflow job for this annotation

GitHub Actions / Code Quality

'StandardisedScoreMigrationTools' does not contain a definition for 'ComputeRank'

Check failure on line 415 in osu.Game/Database/BackgroundDataStoreProcessor.cs

View workflow job for this annotation

GitHub Actions / Code Quality

'StandardisedScoreMigrationTools' does not contain a definition for 'ComputeRank'

Check failure on line 415 in osu.Game/Database/BackgroundDataStoreProcessor.cs

View workflow job for this annotation

GitHub Actions / Test (macOS, macos-latest, SingleThread)

'StandardisedScoreMigrationTools' does not contain a definition for 'ComputeRank'

Check failure on line 415 in osu.Game/Database/BackgroundDataStoreProcessor.cs

View workflow job for this annotation

GitHub Actions / Test (macOS, macos-latest, SingleThread)

'StandardisedScoreMigrationTools' does not contain a definition for 'ComputeRank'

Check failure on line 415 in osu.Game/Database/BackgroundDataStoreProcessor.cs

View workflow job for this annotation

GitHub Actions / Test (macOS, macos-latest, MultiThreaded)

'StandardisedScoreMigrationTools' does not contain a definition for 'ComputeRank'

Check failure on line 415 in osu.Game/Database/BackgroundDataStoreProcessor.cs

View workflow job for this annotation

GitHub Actions / Test (macOS, macos-latest, MultiThreaded)

'StandardisedScoreMigrationTools' does not contain a definition for 'ComputeRank'

Check failure on line 415 in osu.Game/Database/BackgroundDataStoreProcessor.cs

View workflow job for this annotation

GitHub Actions / Test (Linux, ubuntu-latest, SingleThread)

'StandardisedScoreMigrationTools' does not contain a definition for 'ComputeRank'

Check failure on line 415 in osu.Game/Database/BackgroundDataStoreProcessor.cs

View workflow job for this annotation

GitHub Actions / Test (Linux, ubuntu-latest, SingleThread)

'StandardisedScoreMigrationTools' does not contain a definition for 'ComputeRank'

Check failure on line 415 in osu.Game/Database/BackgroundDataStoreProcessor.cs

View workflow job for this annotation

GitHub Actions / Test (Linux, ubuntu-latest, MultiThreaded)

'StandardisedScoreMigrationTools' does not contain a definition for 'ComputeRank'

Check failure on line 415 in osu.Game/Database/BackgroundDataStoreProcessor.cs

View workflow job for this annotation

GitHub Actions / Test (Linux, ubuntu-latest, MultiThreaded)

'StandardisedScoreMigrationTools' does not contain a definition for 'ComputeRank'
});

++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)
Expand Down
3 changes: 2 additions & 1 deletion osu.Game/Scoring/Legacy/LegacyScoreEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ public class LegacyScoreEncoder
/// 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.
Expand Down

0 comments on commit 5d90151

Please sign in to comment.