Skip to content

Commit

Permalink
Merge pull request #212 from tsunyoku/update-pp-for-legacy-scores
Browse files Browse the repository at this point in the history
Backfill PP in `ScorePerformanceProcessor` to `osu_scores_high` on legacy scores
  • Loading branch information
peppy authored Mar 21, 2024
2 parents 219183c + 2ff7ee0 commit 3239554
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ Defaults to `localhost`

Schema version for the queue; see [Schema](https://github.com/ppy/osu-elastic-indexer#schema).

### WRITE_LEGACY_SCORE_PP

Whether to write a legacy score's PP to `osu_scores_high` if applicable to the score. Set to `0` to disable writing.

Default is unset (writing enabled).

## BYO

To setup a testing environment, the minimum requirements are having a MySQL instance available at `localhost:3306` and a redis instance available at `localhost:6379`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public PerformanceProcessorTests()
{
using (var db = Processor.GetDatabaseConnection())
{
db.Execute("TRUNCATE TABLE osu_scores_high");
db.Execute("TRUNCATE TABLE osu_beatmap_difficulty_attribs");
}
}
Expand Down Expand Up @@ -282,6 +283,9 @@ public void LegacyScoreDoesNotProcess()
AddBeatmap();
AddBeatmapAttributes<OsuDifficultyAttributes>();

using (MySqlConnection conn = Processor.GetDatabaseConnection())
conn.Execute("INSERT INTO osu_scores_high (score_id, user_id) VALUES (1, 0)");

ScoreItem score = SetScoreForBeatmap(TEST_BEATMAP_ID, score =>
{
score.Score.ScoreData.Statistics[HitResult.Great] = 100;
Expand All @@ -295,6 +299,11 @@ public void LegacyScoreDoesNotProcess()
{
ScoreId = score.Score.id
});

WaitForDatabaseState("SELECT COUNT(*) FROM osu_scores_high WHERE score_id = 1 AND pp IS NOT NULL", 1, CancellationToken, new
{
ScoreId = score.Score.id
});
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ await ProcessPartitioned(userIds, async userId =>
{
using (var db = DatabaseAccess.GetConnection())
await ScoreProcessor.ProcessUserScoresAsync(userId, RulesetId, db);
Console.WriteLine($"Processed {Interlocked.Increment(ref processedCount)} of {userIds.Length}");
}, cancellationToken);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ await ProcessPartitioned(userIds, async userId =>
{
using (var db = DatabaseAccess.GetConnection())
await ScoreProcessor.ProcessUserScoresAsync(userId, RulesetId, db);
Console.WriteLine($"Processed {Interlocked.Increment(ref processedCount)} of {totalCount}");
}, cancellationToken);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public class ScorePerformanceProcessor : IProcessor

public bool RunOnLegacyScores => false;

private static readonly bool write_legacy_score_pp = Environment.GetEnvironmentVariable("WRITE_LEGACY_SCORE_PP") != "0";

public void RevertFromUserStats(SoloScoreInfo score, UserStats userStats, int previousVersion, MySqlConnection conn, MySqlTransaction transaction)
{
}
Expand Down Expand Up @@ -158,6 +160,16 @@ public async Task ProcessScoreAsync(SoloScoreInfo score, MySqlConnection connect
ScoreId = score.ID,
Pp = performanceAttributes.Total
}, transaction: transaction);

if (score.IsLegacyScore && write_legacy_score_pp)
{
var helper = LegacyDatabaseHelper.GetRulesetSpecifics(score.RulesetID);
await connection.ExecuteAsync($"UPDATE {helper.HighScoreTable} SET pp = @Pp WHERE score_id = @LegacyScoreId", new
{
LegacyScoreId = score.LegacyScoreId,
Pp = performanceAttributes.Total,
}, transaction: transaction);
}
}
catch (Exception ex)
{
Expand Down

0 comments on commit 3239554

Please sign in to comment.