1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 12:57:25 +08:00

Fix beatmap date added not being updated on reimporting a soft deleted beatmap

Addresses concerns raised in https://github.com/ppy/osu/discussions/17399.
This commit is contained in:
Dean Herbert 2022-03-22 14:10:21 +09:00
parent 36772ec652
commit 0fcb3bdba9
3 changed files with 26 additions and 2 deletions

View File

@ -590,6 +590,8 @@ namespace osu.Game.Tests.Database
Assert.IsTrue(imported.DeletePending); Assert.IsTrue(imported.DeletePending);
var originalAddedDate = imported.DateAdded;
var importedSecondTime = await LoadOszIntoStore(importer, realm.Realm); var importedSecondTime = await LoadOszIntoStore(importer, realm.Realm);
// check the newly "imported" beatmap is actually just the restored previous import. since it matches hash. // check the newly "imported" beatmap is actually just the restored previous import. since it matches hash.
@ -597,6 +599,7 @@ namespace osu.Game.Tests.Database
Assert.IsTrue(imported.Beatmaps.First().ID == importedSecondTime.Beatmaps.First().ID); Assert.IsTrue(imported.Beatmaps.First().ID == importedSecondTime.Beatmaps.First().ID);
Assert.IsFalse(imported.DeletePending); Assert.IsFalse(imported.DeletePending);
Assert.IsFalse(importedSecondTime.DeletePending); Assert.IsFalse(importedSecondTime.DeletePending);
Assert.That(importedSecondTime.DateAdded, Is.GreaterThan(originalAddedDate));
}); });
} }
@ -646,6 +649,8 @@ namespace osu.Game.Tests.Database
Assert.IsTrue(imported.DeletePending); Assert.IsTrue(imported.DeletePending);
var originalAddedDate = imported.DateAdded;
var importedSecondTime = await LoadOszIntoStore(importer, realm.Realm); var importedSecondTime = await LoadOszIntoStore(importer, realm.Realm);
// check the newly "imported" beatmap is actually just the restored previous import. since it matches hash. // check the newly "imported" beatmap is actually just the restored previous import. since it matches hash.
@ -653,6 +658,7 @@ namespace osu.Game.Tests.Database
Assert.IsTrue(imported.Beatmaps.First().ID == importedSecondTime.Beatmaps.First().ID); Assert.IsTrue(imported.Beatmaps.First().ID == importedSecondTime.Beatmaps.First().ID);
Assert.IsFalse(imported.DeletePending); Assert.IsFalse(imported.DeletePending);
Assert.IsFalse(importedSecondTime.DeletePending); Assert.IsFalse(importedSecondTime.DeletePending);
Assert.That(importedSecondTime.DateAdded, Is.GreaterThan(originalAddedDate));
}); });
} }

View File

@ -163,6 +163,12 @@ namespace osu.Game.Stores
return existing.OnlineID == import.OnlineID && existingIds.SequenceEqual(importIds); return existing.OnlineID == import.OnlineID && existingIds.SequenceEqual(importIds);
} }
protected override void UndeleteForReuse(BeatmapSetInfo existing)
{
base.UndeleteForReuse(existing);
existing.DateAdded = DateTimeOffset.UtcNow;
}
public override bool IsAvailableLocally(BeatmapSetInfo model) public override bool IsAvailableLocally(BeatmapSetInfo model)
{ {
return Realm.Run(realm => realm.All<BeatmapSetInfo>().Any(s => s.OnlineID == model.OnlineID)); return Realm.Run(realm => realm.All<BeatmapSetInfo>().Any(s => s.OnlineID == model.OnlineID));

View File

@ -351,7 +351,8 @@ namespace osu.Game.Stores
using (var transaction = realm.BeginWrite()) using (var transaction = realm.BeginWrite())
{ {
existing.DeletePending = false; if (existing.DeletePending)
UndeleteForReuse(existing);
transaction.Commit(); transaction.Commit();
} }
@ -387,7 +388,9 @@ namespace osu.Game.Stores
{ {
LogForModel(item, @$"Found existing {HumanisedModelName} for {item} (ID {existing.ID}) skipping import."); LogForModel(item, @$"Found existing {HumanisedModelName} for {item} (ID {existing.ID}) skipping import.");
existing.DeletePending = false; if (existing.DeletePending)
UndeleteForReuse(existing);
transaction.Commit(); transaction.Commit();
return existing.ToLive(Realm); return existing.ToLive(Realm);
@ -527,6 +530,15 @@ namespace osu.Game.Stores
private bool checkAllFilesExist(TModel model) => private bool checkAllFilesExist(TModel model) =>
model.Files.All(f => Files.Storage.Exists(f.File.GetStoragePath())); model.Files.All(f => Files.Storage.Exists(f.File.GetStoragePath()));
/// <summary>
/// Called when an existing model is in a soft deleted state but being recovered.
/// </summary>
/// <param name="existing">The existing model.</param>
protected virtual void UndeleteForReuse(TModel existing)
{
existing.DeletePending = false;
}
/// <summary> /// <summary>
/// Whether this specified path should be removed after successful import. /// Whether this specified path should be removed after successful import.
/// </summary> /// </summary>