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

Move 'transferCollections' to a shared location

This commit is contained in:
pfg 2022-10-10 21:45:33 -04:00
parent 7726dda975
commit de8d485305
3 changed files with 14 additions and 12 deletions

View File

@ -146,13 +146,7 @@ namespace osu.Game.Beatmaps
if (updatedBeatmap == null)
continue;
var collections = realm.All<BeatmapCollection>().AsEnumerable().Where(c => c.BeatmapMD5Hashes.Contains(originalBeatmap.MD5Hash));
foreach (var c in collections)
{
c.BeatmapMD5Hashes.Remove(originalBeatmap.MD5Hash);
c.BeatmapMD5Hashes.Add(updatedBeatmap.MD5Hash);
}
updatedBeatmap.transferCollectionsFrom(realm, originalBeatmap.MD5Hash);
}
}

View File

@ -8,6 +8,7 @@ using JetBrains.Annotations;
using Newtonsoft.Json;
using osu.Framework.Testing;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Collections;
using osu.Game.Database;
using osu.Game.Models;
using osu.Game.Online.API.Requests.Responses;
@ -213,6 +214,17 @@ namespace osu.Game.Beatmaps
return fileHashX == fileHashY;
}
public void transferCollectionsFrom(Realm realm, string oldMd5Hash)
{
var collections = realm.All<BeatmapCollection>().AsEnumerable().Where(c => c.BeatmapMD5Hashes.Contains(oldMd5Hash));
foreach (var c in collections)
{
c.BeatmapMD5Hashes.Remove(oldMd5Hash);
c.BeatmapMD5Hashes.Add(MD5Hash);
}
}
IBeatmapMetadataInfo IBeatmapInfo.Metadata => Metadata;
IBeatmapSetInfo? IBeatmapInfo.BeatmapSet => BeatmapSet;
IRulesetInfo IBeatmapInfo.Ruleset => Ruleset;

View File

@ -330,11 +330,7 @@ namespace osu.Game.Beatmaps
setInfo.CopyChangesToRealm(liveBeatmapSet);
foreach (var collection in r.All<BeatmapCollection>())
{
if (collection.BeatmapMD5Hashes.Remove(oldMd5Hash))
collection.BeatmapMD5Hashes.Add(beatmapInfo.MD5Hash);
}
beatmapInfo.transferCollectionsFrom(r, oldMd5Hash);
ProcessBeatmap?.Invoke((liveBeatmapSet, false));
});