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

Merge pull request #24210 from OliBomby/fast-save

Optimize editor save action for huge Realm database
This commit is contained in:
Dean Herbert 2023-07-13 23:39:23 +09:00 committed by GitHub
commit b60c0c090d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -431,8 +431,9 @@ namespace osu.Game.Beatmaps
beatmapInfo.Status = BeatmapOnlineStatus.LocallyModified; beatmapInfo.Status = BeatmapOnlineStatus.LocallyModified;
beatmapInfo.ResetOnlineInfo(); beatmapInfo.ResetOnlineInfo();
using (var stream = new MemoryStream()) Realm.Write(r =>
{ {
using var stream = new MemoryStream();
using (var sw = new StreamWriter(stream, Encoding.UTF8, 1024, true)) using (var sw = new StreamWriter(stream, Encoding.UTF8, 1024, true))
new LegacyBeatmapEncoder(beatmapContent, beatmapSkin).Encode(sw); new LegacyBeatmapEncoder(beatmapContent, beatmapSkin).Encode(sw);
@ -458,23 +459,20 @@ namespace osu.Game.Beatmaps
updateHashAndMarkDirty(setInfo); updateHashAndMarkDirty(setInfo);
Realm.Write(r => var liveBeatmapSet = r.Find<BeatmapSetInfo>(setInfo.ID)!;
{
var liveBeatmapSet = r.Find<BeatmapSetInfo>(setInfo.ID)!;
setInfo.CopyChangesToRealm(liveBeatmapSet); setInfo.CopyChangesToRealm(liveBeatmapSet);
if (transferCollections) if (transferCollections)
beatmapInfo.TransferCollectionReferences(r, oldMd5Hash); beatmapInfo.TransferCollectionReferences(r, oldMd5Hash);
liveBeatmapSet.Beatmaps.Single(b => b.ID == beatmapInfo.ID) liveBeatmapSet.Beatmaps.Single(b => b.ID == beatmapInfo.ID)
.UpdateLocalScores(r); .UpdateLocalScores(r);
// do not look up metadata. // do not look up metadata.
// this is a locally-modified set now, so looking up metadata is busy work at best and harmful at worst. // this is a locally-modified set now, so looking up metadata is busy work at best and harmful at worst.
ProcessBeatmap?.Invoke(liveBeatmapSet, MetadataLookupScope.None); ProcessBeatmap?.Invoke(liveBeatmapSet, MetadataLookupScope.None);
}); });
}
Debug.Assert(beatmapInfo.BeatmapSet != null); Debug.Assert(beatmapInfo.BeatmapSet != null);