Merge pull request #17401 from peppy/update-date-added-on-use-existing

Fix beatmap date added not being updated on reimporting a soft deleted beatmap
This commit is contained in:
Dan Balasescu 2022-03-22 14:41:07 +09:00 committed by GitHub
commit 056e568ffb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 2 deletions

View File

@ -590,6 +590,8 @@ namespace osu.Game.Tests.Database
Assert.IsTrue(imported.DeletePending);
var originalAddedDate = imported.DateAdded;
var importedSecondTime = await LoadOszIntoStore(importer, realm.Realm);
// 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.IsFalse(imported.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);
var originalAddedDate = imported.DateAdded;
var importedSecondTime = await LoadOszIntoStore(importer, realm.Realm);
// 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.IsFalse(imported.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);
}
protected override void UndeleteForReuse(BeatmapSetInfo existing)
{
base.UndeleteForReuse(existing);
existing.DateAdded = DateTimeOffset.UtcNow;
}
public override bool IsAvailableLocally(BeatmapSetInfo model)
{
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())
{
existing.DeletePending = false;
if (existing.DeletePending)
UndeleteForReuse(existing);
transaction.Commit();
}
@ -387,7 +388,9 @@ namespace osu.Game.Stores
{
LogForModel(item, @$"Found existing {HumanisedModelName} for {item} (ID {existing.ID}) skipping import.");
existing.DeletePending = false;
if (existing.DeletePending)
UndeleteForReuse(existing);
transaction.Commit();
return existing.ToLive(Realm);
@ -527,6 +530,15 @@ namespace osu.Game.Stores
private bool checkAllFilesExist(TModel model) =>
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>
/// Whether this specified path should be removed after successful import.
/// </summary>