From bbaa542d4a376e490c7e58d794ff49ca7e1bdddb Mon Sep 17 00:00:00 2001 From: Dean Herbert <pe@ppy.sh> Date: Tue, 10 Dec 2024 16:44:35 +0900 Subject: [PATCH] Add note about expensive operation --- osu.Game/Screens/Edit/Setup/ResourcesSection.cs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/osu.Game/Screens/Edit/Setup/ResourcesSection.cs b/osu.Game/Screens/Edit/Setup/ResourcesSection.cs index 6cde0e6792..7fcd09d7e7 100644 --- a/osu.Game/Screens/Edit/Setup/ResourcesSection.cs +++ b/osu.Game/Screens/Edit/Setup/ResourcesSection.cs @@ -148,14 +148,17 @@ namespace osu.Game.Screens.Edit.Setup { foreach (var b in otherBeatmaps) { - if (readFilename(b.Metadata) != newFilename) - { - writeFilename(b.Metadata, newFilename); + // This operation is quite expensive, so only perform it if required. + if (readFilename(b.Metadata) == newFilename) continue; - // save the difficulty to re-encode the .osu file, updating any reference of the old filename. - var beatmapWorking = beatmaps.GetWorkingBeatmap(b); - beatmaps.Save(b, beatmapWorking.Beatmap, beatmapWorking.GetSkin()); - } + writeFilename(b.Metadata, newFilename); + + // save the difficulty to re-encode the .osu file, updating any reference of the old filename. + // + // note that this triggers a full save flow, including triggering a difficulty calculation. + // this is not a cheap operation and should be reconsidered in the future. + var beatmapWorking = beatmaps.GetWorkingBeatmap(b); + beatmaps.Save(b, beatmapWorking.Beatmap, beatmapWorking.GetSkin()); } }