mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 14:32:55 +08:00
Extract update into PreUpdate(), add test
This commit is contained in:
parent
fac96f6ddd
commit
dfb9687fb5
@ -602,6 +602,8 @@ namespace osu.Game.Tests.Beatmaps.IO
|
||||
Beatmap beatmapToUpdate = (Beatmap)manager.GetWorkingBeatmap(setToUpdate.Beatmaps.First(b => b.RulesetID == 0)).Beatmap;
|
||||
BeatmapSetFileInfo fileToUpdate = setToUpdate.Files.First(f => beatmapToUpdate.BeatmapInfo.Path.Contains(f.Filename));
|
||||
|
||||
string oldMd5Hash = beatmapToUpdate.BeatmapInfo.MD5Hash;
|
||||
|
||||
using (var stream = new MemoryStream())
|
||||
{
|
||||
using (var writer = new StreamWriter(stream, Encoding.UTF8, 1024, true))
|
||||
@ -624,6 +626,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
||||
Beatmap updatedBeatmap = (Beatmap)manager.GetWorkingBeatmap(manager.QueryBeatmap(b => b.ID == beatmapToUpdate.BeatmapInfo.ID)).Beatmap;
|
||||
Assert.That(updatedBeatmap.HitObjects.Count, Is.EqualTo(1));
|
||||
Assert.That(updatedBeatmap.HitObjects[0].StartTime, Is.EqualTo(5000));
|
||||
Assert.That(updatedBeatmap.BeatmapInfo.MD5Hash, Is.Not.EqualTo(oldMd5Hash));
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
@ -201,10 +201,6 @@ namespace osu.Game.Beatmaps
|
||||
using (var sw = new StreamWriter(stream, Encoding.UTF8, 1024, true))
|
||||
new LegacyBeatmapEncoder(beatmapContent).Encode(sw);
|
||||
|
||||
var attachedInfo = setInfo.Beatmaps.Single(b => b.ID == info.ID);
|
||||
var md5Hash = stream.ComputeMD5Hash();
|
||||
attachedInfo.MD5Hash = md5Hash;
|
||||
|
||||
UpdateFile(setInfo, setInfo.Files.Single(f => string.Equals(f.Filename, info.Path, StringComparison.OrdinalIgnoreCase)), stream);
|
||||
}
|
||||
|
||||
@ -213,6 +209,19 @@ namespace osu.Game.Beatmaps
|
||||
workingCache.Remove(working);
|
||||
}
|
||||
|
||||
protected override void PreUpdate(BeatmapSetInfo item)
|
||||
{
|
||||
base.PreUpdate(item);
|
||||
|
||||
foreach (var info in item.Beatmaps)
|
||||
{
|
||||
var file = item.Files.FirstOrDefault(f => string.Equals(f.Filename, info.Path, StringComparison.OrdinalIgnoreCase))?.FileInfo.StoragePath;
|
||||
|
||||
using (var stream = Files.Store.GetStream(file))
|
||||
info.MD5Hash = stream.ComputeMD5Hash();
|
||||
}
|
||||
}
|
||||
|
||||
private readonly WeakList<WorkingBeatmap> workingCache = new WeakList<WorkingBeatmap>();
|
||||
|
||||
/// <summary>
|
||||
|
@ -430,10 +430,20 @@ namespace osu.Game.Database
|
||||
{
|
||||
item.Hash = computeHash(item);
|
||||
|
||||
PreUpdate(item);
|
||||
|
||||
ModelStore.Update(item);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Perform any final actions before the update to database executes.
|
||||
/// </summary>
|
||||
/// <param name="item">The <typeparamref name="TModel"/> that is being updated.</param>
|
||||
protected virtual void PreUpdate(TModel item)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete an item from the manager.
|
||||
/// Is a no-op for already deleted items.
|
||||
|
Loading…
Reference in New Issue
Block a user