Skip to content

Commit

Permalink
Move score re-attach to PostImport
Browse files Browse the repository at this point in the history
  • Loading branch information
peppy committed Jul 1, 2023
1 parent 8d25e2c commit a4a9223
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions osu.Game/Beatmaps/BeatmapImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,21 +200,22 @@ protected override void PreImport(BeatmapSetInfo beatmapSet, Realm realm)
LogForModel(beatmapSet, $"Found existing beatmap set with same OnlineID ({beatmapSet.OnlineID}). It will be disassociated and marked for deletion.");
}
}
}

protected override void PostImport(BeatmapSetInfo model, Realm realm, ImportParameters parameters)
{
base.PostImport(model, realm, parameters);

//Because of specific score storing in Osu! database, it can already contain scores for imported beatmap.
//To restore scores we need to manually reassign them to new/re-exported beatmap.
foreach (BeatmapInfo beatmap in beatmapSet.Beatmaps)
foreach (BeatmapInfo beatmap in model.Beatmaps)
{
IQueryable<ScoreInfo> scores = realm.All<ScoreInfo>().Where(score => score.BeatmapHash == beatmap.Hash);

if (scores.Any())
scores.ForEach(score => score.BeatmapInfo = beatmap); //We intentionally ignore BeatmapHash because we checked hash equality
}
}

protected override void PostImport(BeatmapSetInfo model, Realm realm, ImportParameters parameters)
{
base.PostImport(model, realm, parameters);
ProcessBeatmap?.Invoke(model, parameters.Batch ? MetadataLookupScope.LocalCacheFirst : MetadataLookupScope.OnlineFirst);
}

Expand Down

0 comments on commit a4a9223

Please sign in to comment.