Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop marking scores as ranked = 0 for pp only purposes #227

Merged
merged 1 commit into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
};

foreach (var mod in mods)
Assert.True(ScorePerformanceProcessor.AllModsValidForPerformance(new SoloScoreInfo(), new[] { mod }), mod.GetType().ReadableName());

Check notice on line 144 in osu.Server.Queues.ScoreStatisticsProcessor.Tests/PerformanceProcessorTests.cs

View workflow job for this annotation

GitHub Actions / Code Quality

Use collection expression in osu.Server.Queues.ScoreStatisticsProcessor.Tests\PerformanceProcessorTests.cs on line 144
}

[Fact]
Expand Down Expand Up @@ -173,7 +173,7 @@
};

foreach (var mod in mods)
Assert.False(ScorePerformanceProcessor.AllModsValidForPerformance(new SoloScoreInfo(), new[] { mod }), mod.GetType().ReadableName());

Check notice on line 176 in osu.Server.Queues.ScoreStatisticsProcessor.Tests/PerformanceProcessorTests.cs

View workflow job for this annotation

GitHub Actions / Code Quality

Use collection expression in osu.Server.Queues.ScoreStatisticsProcessor.Tests\PerformanceProcessorTests.cs on line 176
}

[Fact]
Expand Down Expand Up @@ -309,14 +309,14 @@
score.Score.preserve = true;
});

WaitForDatabaseState("SELECT COUNT(*) FROM scores WHERE id = @ScoreId AND ranked = 0", 1, CancellationToken, new
WaitForDatabaseState("SELECT COUNT(*) FROM scores WHERE id = @ScoreId AND pp IS NULL", 1, CancellationToken, new
{
ScoreId = score.Score.id
});
}

[Fact]
public void ScoresThatHavePpButInvalidModsIsNotRanked()
public void ScoresThatHavePpButInvalidModsGetsNoPP()
{
AddBeatmap();
AddBeatmapAttributes<OsuDifficultyAttributes>();
Expand All @@ -332,15 +332,14 @@
score.Score.accuracy = 1;
score.Score.build_id = TestBuildID;
score.Score.ScoreData.Mods = new[] { new APIMod(new InvalidMod()) };
score.Score.pp = 1;
score.Score.preserve = true;

conn.Insert(score.Score);

PushToQueueAndWaitForProcess(score);
}

WaitForDatabaseState("SELECT COUNT(*) FROM scores WHERE id = @ScoreId AND ranked = 0", 1, CancellationToken, new
WaitForDatabaseState("SELECT COUNT(*) FROM scores WHERE id = @ScoreId AND pp IS NULL", 1, CancellationToken, new
{
ScoreId = score.Score.id
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,52 +125,33 @@ public async Task ProcessScoreAsync(SoloScoreInfo score, MySqlConnection connect
Beatmap? beatmap = await beatmapStore.GetBeatmapAsync((uint)score.BeatmapID, connection, transaction);

if (beatmap == null)
{
await markNonRanked();

return;
}

if (!beatmapStore.IsBeatmapValidForPerformance(beatmap, (uint)score.RulesetID))
{
await markNonRanked();
return;
}

Ruleset ruleset = LegacyRulesetHelper.GetRulesetFromLegacyId(score.RulesetID);
Mod[] mods = score.Mods.Select(m => m.ToMod(ruleset)).ToArray();

if (!AllModsValidForPerformance(score, mods))
{
await markNonRanked();
return;
}

APIBeatmap apiBeatmap = beatmap.ToAPIBeatmap();
DifficultyAttributes? difficultyAttributes = await beatmapStore.GetDifficultyAttributesAsync(apiBeatmap, ruleset, mods, connection, transaction);

// Performance needs to be allowed for the build.
// legacy scores don't need a build id
if (score.LegacyScoreId == null && (score.BuildID == null || buildStore.GetBuild(score.BuildID.Value)?.allow_performance != true))
{
await markNonRanked();
return;
}

if (difficultyAttributes == null)
{
await markNonRanked();
return;
}

ScoreInfo scoreInfo = score.ToScoreInfo(mods, apiBeatmap);
PerformanceAttributes? performanceAttributes = ruleset.CreatePerformanceCalculator()?.Calculate(scoreInfo, difficultyAttributes);

if (performanceAttributes == null)
{
await markNonRanked();
return;
}

await connection.ExecuteAsync("UPDATE scores SET pp = @Pp WHERE id = @ScoreId", new
{
Expand All @@ -182,15 +163,6 @@ public async Task ProcessScoreAsync(SoloScoreInfo score, MySqlConnection connect
{
await Console.Error.WriteLineAsync($"{score.ID} failed with: {ex}");
}

// TODO: this should probably just update the model once we switch to SoloScore (the local updated class).
Task<int> markNonRanked()
{
return connection.ExecuteAsync("UPDATE scores SET ranked = 0 WHERE id = @ScoreId", new
{
ScoreId = score.ID,
}, transaction: transaction);
}
}

/// <summary>
Expand Down