-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30526 from smoogipoo/fix-beatmap-recommender-test
Fix intermittent beatmap recommendations test
- Loading branch information
Showing
6 changed files
with
115 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
@@ -15,10 +14,7 @@ | |
|
||
namespace osu.Game.Beatmaps | ||
{ | ||
/// <summary> | ||
/// Handles all processing required to ensure a local beatmap is in a consistent state with any changes. | ||
/// </summary> | ||
public class BeatmapUpdater : IDisposable | ||
public class BeatmapUpdater : IBeatmapUpdater | ||
{ | ||
private readonly IWorkingBeatmapCache workingBeatmapCache; | ||
|
||
|
@@ -38,67 +34,63 @@ public BeatmapUpdater(IWorkingBeatmapCache workingBeatmapCache, BeatmapDifficult | |
metadataLookup = new BeatmapUpdaterMetadataLookup(api, storage); | ||
} | ||
|
||
/// <summary> | ||
/// Queue a beatmap for background processing. | ||
/// </summary> | ||
/// <param name="beatmapSet">The managed beatmap set to update. A transaction will be opened to apply changes.</param> | ||
/// <param name="lookupScope">The preferred scope to use for metadata lookup.</param> | ||
public void Queue(Live<BeatmapSetInfo> beatmapSet, MetadataLookupScope lookupScope = MetadataLookupScope.LocalCacheFirst) | ||
{ | ||
Logger.Log($"Queueing change for local beatmap {beatmapSet}"); | ||
Task.Factory.StartNew(() => beatmapSet.PerformRead(b => Process(b, lookupScope)), default, TaskCreationOptions.HideScheduler | TaskCreationOptions.RunContinuationsAsynchronously, | ||
updateScheduler); | ||
} | ||
|
||
/// <summary> | ||
/// Run all processing on a beatmap immediately. | ||
/// </summary> | ||
/// <param name="beatmapSet">The managed beatmap set to update. A transaction will be opened to apply changes.</param> | ||
/// <param name="lookupScope">The preferred scope to use for metadata lookup.</param> | ||
public void Process(BeatmapSetInfo beatmapSet, MetadataLookupScope lookupScope = MetadataLookupScope.LocalCacheFirst) => beatmapSet.Realm!.Write(_ => | ||
public void Process(BeatmapSetInfo beatmapSet, MetadataLookupScope lookupScope = MetadataLookupScope.LocalCacheFirst) | ||
{ | ||
// Before we use below, we want to invalidate. | ||
workingBeatmapCache.Invalidate(beatmapSet); | ||
beatmapSet.Realm!.Write(_ => | ||
{ | ||
// Before we use below, we want to invalidate. | ||
workingBeatmapCache.Invalidate(beatmapSet); | ||
|
||
if (lookupScope != MetadataLookupScope.None) | ||
metadataLookup.Update(beatmapSet, lookupScope == MetadataLookupScope.OnlineFirst); | ||
if (lookupScope != MetadataLookupScope.None) | ||
metadataLookup.Update(beatmapSet, lookupScope == MetadataLookupScope.OnlineFirst); | ||
|
||
foreach (var beatmap in beatmapSet.Beatmaps) | ||
{ | ||
difficultyCache.Invalidate(beatmap); | ||
foreach (var beatmap in beatmapSet.Beatmaps) | ||
{ | ||
difficultyCache.Invalidate(beatmap); | ||
|
||
var working = workingBeatmapCache.GetWorkingBeatmap(beatmap); | ||
var ruleset = working.BeatmapInfo.Ruleset.CreateInstance(); | ||
var working = workingBeatmapCache.GetWorkingBeatmap(beatmap); | ||
var ruleset = working.BeatmapInfo.Ruleset.CreateInstance(); | ||
|
||
Debug.Assert(ruleset != null); | ||
Debug.Assert(ruleset != null); | ||
|
||
var calculator = ruleset.CreateDifficultyCalculator(working); | ||
var calculator = ruleset.CreateDifficultyCalculator(working); | ||
|
||
beatmap.StarRating = calculator.Calculate().StarRating; | ||
beatmap.Length = working.Beatmap.CalculatePlayableLength(); | ||
beatmap.BPM = 60000 / working.Beatmap.GetMostCommonBeatLength(); | ||
beatmap.EndTimeObjectCount = working.Beatmap.HitObjects.Count(h => h is IHasDuration); | ||
beatmap.TotalObjectCount = working.Beatmap.HitObjects.Count; | ||
} | ||
beatmap.StarRating = calculator.Calculate().StarRating; | ||
beatmap.Length = working.Beatmap.CalculatePlayableLength(); | ||
beatmap.BPM = 60000 / working.Beatmap.GetMostCommonBeatLength(); | ||
beatmap.EndTimeObjectCount = working.Beatmap.HitObjects.Count(h => h is IHasDuration); | ||
beatmap.TotalObjectCount = working.Beatmap.HitObjects.Count; | ||
} | ||
|
||
// And invalidate again afterwards as re-fetching the most up-to-date database metadata will be required. | ||
workingBeatmapCache.Invalidate(beatmapSet); | ||
}); | ||
// And invalidate again afterwards as re-fetching the most up-to-date database metadata will be required. | ||
workingBeatmapCache.Invalidate(beatmapSet); | ||
}); | ||
} | ||
|
||
public void ProcessObjectCounts(BeatmapInfo beatmapInfo, MetadataLookupScope lookupScope = MetadataLookupScope.LocalCacheFirst) => beatmapInfo.Realm!.Write(_ => | ||
public void ProcessObjectCounts(BeatmapInfo beatmapInfo, MetadataLookupScope lookupScope = MetadataLookupScope.LocalCacheFirst) | ||
{ | ||
// Before we use below, we want to invalidate. | ||
workingBeatmapCache.Invalidate(beatmapInfo); | ||
beatmapInfo.Realm!.Write(_ => | ||
{ | ||
// Before we use below, we want to invalidate. | ||
workingBeatmapCache.Invalidate(beatmapInfo); | ||
|
||
var working = workingBeatmapCache.GetWorkingBeatmap(beatmapInfo); | ||
var beatmap = working.Beatmap; | ||
var working = workingBeatmapCache.GetWorkingBeatmap(beatmapInfo); | ||
var beatmap = working.Beatmap; | ||
|
||
beatmapInfo.EndTimeObjectCount = beatmap.HitObjects.Count(h => h is IHasDuration); | ||
beatmapInfo.TotalObjectCount = beatmap.HitObjects.Count; | ||
beatmapInfo.EndTimeObjectCount = beatmap.HitObjects.Count(h => h is IHasDuration); | ||
beatmapInfo.TotalObjectCount = beatmap.HitObjects.Count; | ||
|
||
// And invalidate again afterwards as re-fetching the most up-to-date database metadata will be required. | ||
workingBeatmapCache.Invalidate(beatmapInfo); | ||
}); | ||
// And invalidate again afterwards as re-fetching the most up-to-date database metadata will be required. | ||
workingBeatmapCache.Invalidate(beatmapInfo); | ||
}); | ||
} | ||
|
||
#region Implementation of IDisposable | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System; | ||
using osu.Game.Database; | ||
|
||
namespace osu.Game.Beatmaps | ||
{ | ||
/// <summary> | ||
/// Handles all processing required to ensure a local beatmap is in a consistent state with any changes. | ||
/// </summary> | ||
public interface IBeatmapUpdater : IDisposable | ||
{ | ||
/// <summary> | ||
/// Queue a beatmap for background processing. | ||
/// </summary> | ||
/// <param name="beatmapSet">The managed beatmap set to update. A transaction will be opened to apply changes.</param> | ||
/// <param name="lookupScope">The preferred scope to use for metadata lookup.</param> | ||
void Queue(Live<BeatmapSetInfo> beatmapSet, MetadataLookupScope lookupScope = MetadataLookupScope.LocalCacheFirst); | ||
|
||
/// <summary> | ||
/// Run all processing on a beatmap immediately. | ||
/// </summary> | ||
/// <param name="beatmapSet">The managed beatmap set to update. A transaction will be opened to apply changes.</param> | ||
/// <param name="lookupScope">The preferred scope to use for metadata lookup.</param> | ||
void Process(BeatmapSetInfo beatmapSet, MetadataLookupScope lookupScope = MetadataLookupScope.LocalCacheFirst); | ||
|
||
/// <summary> | ||
/// Runs a subset of processing focused on updating any cached beatmap object counts. | ||
/// </summary> | ||
/// <param name="beatmapInfo">The managed beatmap to update. A transaction will be opened to apply changes.</param> | ||
/// <param name="lookupScope">The preferred scope to use for metadata lookup.</param> | ||
void ProcessObjectCounts(BeatmapInfo beatmapInfo, MetadataLookupScope lookupScope = MetadataLookupScope.LocalCacheFirst); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters