Skip to content

Commit 8d38b2e

Browse files
authored
Merge pull request #55 from bdach/reviving-with-no-changes-should-work
Bump beatmap set last update date even if the contents didn't change
2 parents 9486694 + c74e6dd commit 8d38b2e

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

osu.Server.BeatmapSubmission.Tests/BeatmapSubmissionControllerTest.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1839,6 +1839,44 @@ osu file format v14
18391839
}
18401840
}
18411841

1842+
[Fact]
1843+
public async Task TestPatch_BeatmapWithNoChanges_BumpsLastUpdateDate()
1844+
{
1845+
using var db = await DatabaseAccess.GetConnectionAsync();
1846+
await db.ExecuteAsync(
1847+
"INSERT INTO `phpbb_users` (`user_id`, `username`, `username_clean`, `country_acronym`, `user_permissions`, `user_sig`, `user_occ`, `user_interests`) VALUES (1000, 'test', 'test', 'JP', '', '', '', '')");
1848+
1849+
await db.ExecuteAsync(
1850+
@"INSERT INTO `osu_beatmapsets` (`beatmapset_id`, `user_id`, `creator`, `approved`, `thread_id`, `active`, `submit_date`) VALUES (241526, 1000, 'test user', -1, 0, -1, CURRENT_TIMESTAMP)");
1851+
1852+
foreach (uint beatmapId in new uint[] { 557815, 557814, 557821, 557816, 557817, 557818, 557812, 557810, 557811, 557820, 557813, 557819 })
1853+
await db.ExecuteAsync(@"INSERT INTO `osu_beatmaps` (`beatmap_id`, `user_id`, `beatmapset_id`, `approved`) VALUES (@beatmapId, 1000, 241526, -1)", new { beatmapId = beatmapId });
1854+
1855+
// do a full upload first - required to correctly populate versioning tables
1856+
var putRequest = new HttpRequestMessage(HttpMethod.Put, "/beatmapsets/241526");
1857+
1858+
using var content = new MultipartFormDataContent($"{Guid.NewGuid()}----");
1859+
using var stream = TestResources.GetResource(osz_filename)!;
1860+
content.Add(new StreamContent(stream), "beatmapArchive", osz_filename);
1861+
putRequest.Content = content;
1862+
putRequest.Headers.Add(HeaderBasedAuthenticationHandler.USER_ID_HEADER, "1000");
1863+
1864+
var putResponse = await Client.SendAsync(putRequest);
1865+
Assert.True(putResponse.IsSuccessStatusCode);
1866+
1867+
// manually doctor the beatmapset's last update date to make sure it's bumped on a no-op patch
1868+
await db.ExecuteAsync(@"UPDATE `osu_beatmapsets` SET `last_update` = '2020-01-01 00:00:00' WHERE `beatmapset_id` = 241526");
1869+
1870+
// perform a no-op patch
1871+
var patchRequest = new HttpRequestMessage(HttpMethod.Patch, "/beatmapsets/241526");
1872+
patchRequest.Headers.Add(HeaderBasedAuthenticationHandler.USER_ID_HEADER, "1000");
1873+
1874+
var response = await Client.SendAsync(patchRequest);
1875+
Assert.True(response.IsSuccessStatusCode);
1876+
1877+
WaitForDatabaseState(@"SELECT COUNT(1) FROM `osu_beatmapsets` WHERE `beatmapset_id` = 241526 AND `last_update` > '2020-01-01 00:00:00'", 1, CancellationToken);
1878+
}
1879+
18421880
[Fact]
18431881
public async Task TestSubmitGuestDifficulty_OldStyle()
18441882
{

osu.Server.BeatmapSubmission/BeatmapSubmissionController.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,8 @@ private async Task<bool> updateBeatmapSetFromArchiveAsync(osu_beatmapset beatmap
421421

422422
if (fileSet.SetEquals(parseResult.Files))
423423
{
424-
await transaction.RollbackAsync();
424+
await db.MarkBeatmapSetUpdatedAsync(beatmapSet, transaction);
425+
await transaction.CommitAsync();
425426
return false;
426427
}
427428
}

osu.Server.BeatmapSubmission/DatabaseOperationExtensions.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,17 @@ public static Task UpdateBeatmapSetAsync(this MySqlConnection db, osu_beatmapset
295295
transaction);
296296
}
297297

298+
/// <summary>
299+
/// Only bumps the <paramref name="beatmapset"/>'s <c>last_update</c> date without performing any other changes.
300+
/// Used in scenarios where a submission occurred for a beatmap with no changes.
301+
/// Bumping the update date is important in such cases, because if it is e.g. an update after reviving the beatmap,
302+
/// not bumping the update date will cause the beatmap to move to the graveyard again on the next day after the update.
303+
/// </summary>
304+
public static Task MarkBeatmapSetUpdatedAsync(this MySqlConnection db, osu_beatmapset beatmapset, MySqlTransaction? transaction = null)
305+
{
306+
return db.ExecuteAsync("UPDATE `osu_beatmapsets` SET `last_update` = CURRENT_TIMESTAMP WHERE `beatmapset_id` = @beatmapset_id", beatmapset, transaction);
307+
}
308+
298309
public static async Task<ulong> InsertBeatmapsetFileAsync(this MySqlConnection db, beatmapset_file file, MySqlTransaction? transaction = null)
299310
{
300311
var existing = await db.QuerySingleOrDefaultAsync<beatmapset_file?>(

0 commit comments

Comments
 (0)