mirror of
https://github.com/ppy/osu.git
synced 2025-03-22 13:17:45 +08:00
Access database recursively.
This commit is contained in:
parent
146d57953d
commit
767cfaaac3
@ -118,7 +118,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
||||
Action waitAction = () =>
|
||||
{
|
||||
while (!(resultSets = host.Dependencies.Get<BeatmapDatabase>()
|
||||
.Query<BeatmapSetInfo>().Where(s => s.OnlineBeatmapSetID == 241526)).Any())
|
||||
.GetAllWithChildren<BeatmapSetInfo>(s => s.OnlineBeatmapSetID == 241526)).Any())
|
||||
Thread.Sleep(50);
|
||||
};
|
||||
|
||||
@ -135,15 +135,14 @@ namespace osu.Game.Tests.Beatmaps.IO
|
||||
waitAction = () =>
|
||||
{
|
||||
while ((resultBeatmaps = host.Dependencies.Get<BeatmapDatabase>()
|
||||
.Query<BeatmapInfo>().Where(s => s.OnlineBeatmapSetID == 241526 && s.BaseDifficultyID > 0)).Count() != 12)
|
||||
.GetAllWithChildren<BeatmapInfo>(s => s.OnlineBeatmapSetID == 241526 && s.BaseDifficultyID > 0)).Count() != 12)
|
||||
Thread.Sleep(50);
|
||||
};
|
||||
|
||||
Assert.IsTrue(waitAction.BeginInvoke(null, null).AsyncWaitHandle.WaitOne(timeout),
|
||||
@"Beatmaps did not import to the database in allocated time");
|
||||
|
||||
//fetch children and check we can load from the post-storage path...
|
||||
var set = host.Dependencies.Get<BeatmapDatabase>().GetChildren(resultSets.First());
|
||||
var set = resultSets.First();
|
||||
|
||||
Assert.IsTrue(set.Beatmaps.Count == resultBeatmaps.Count(),
|
||||
$@"Incorrect database beatmap count post-import ({resultBeatmaps.Count()} but should be {set.Beatmaps.Count}).");
|
||||
|
@ -36,14 +36,12 @@ namespace osu.Game.Database
|
||||
|
||||
private void deletePending()
|
||||
{
|
||||
foreach (var b in Query<BeatmapSetInfo>().Where(b => b.DeletePending))
|
||||
foreach (var b in GetAllWithChildren<BeatmapSetInfo>(b => b.DeletePending))
|
||||
{
|
||||
try
|
||||
{
|
||||
Storage.Delete(b.Path);
|
||||
|
||||
GetChildren(b, true);
|
||||
|
||||
foreach (var i in b.Beatmaps)
|
||||
{
|
||||
if (i.Metadata != null) Connection.Delete(i.Metadata);
|
||||
@ -269,20 +267,11 @@ namespace osu.Game.Database
|
||||
|
||||
public WorkingBeatmap GetWorkingBeatmap(BeatmapInfo beatmapInfo, WorkingBeatmap previous = null, bool withStoryboard = false)
|
||||
{
|
||||
var beatmapSetInfo = Query<BeatmapSetInfo>().FirstOrDefault(s => s.ID == beatmapInfo.BeatmapSetInfoID);
|
||||
|
||||
if (beatmapSetInfo == null)
|
||||
if (beatmapInfo.BeatmapSet == null)
|
||||
throw new InvalidOperationException($@"Beatmap set {beatmapInfo.BeatmapSetInfoID} is not in the local database.");
|
||||
|
||||
beatmapInfo.BeatmapSet = beatmapSetInfo;
|
||||
|
||||
//we need metadata
|
||||
GetChildren(beatmapSetInfo);
|
||||
//we also need a ruleset
|
||||
GetChildren(beatmapInfo);
|
||||
|
||||
if (beatmapInfo.Metadata == null)
|
||||
beatmapInfo.Metadata = beatmapSetInfo.Metadata;
|
||||
beatmapInfo.Metadata = beatmapInfo.BeatmapSet.Metadata;
|
||||
|
||||
WorkingBeatmap working = new DatabaseWorkingBeatmap(this, beatmapInfo, withStoryboard: withStoryboard);
|
||||
|
||||
|
@ -48,9 +48,9 @@ namespace osu.Game.Database
|
||||
return Connection.Table<T>();
|
||||
}
|
||||
|
||||
public T GetWithChildren<T>(object id) where T : class
|
||||
public T GetWithChildren<T>(object id, bool recursive = false) where T : class
|
||||
{
|
||||
return Connection.GetWithChildren<T>(id);
|
||||
return Connection.GetWithChildren<T>(id, recursive);
|
||||
}
|
||||
|
||||
public List<T> GetAllWithChildren<T>(Expression<Func<T, bool>> filter = null, bool recursive = true)
|
||||
|
@ -1,13 +1,16 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System.Threading.Tasks;
|
||||
using OpenTK;
|
||||
using OpenTK.Input;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Audio.Track;
|
||||
using osu.Framework.Configuration;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Input;
|
||||
using osu.Framework.MathUtils;
|
||||
using osu.Framework.Screens;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Database;
|
||||
using osu.Game.Graphics.Containers;
|
||||
@ -16,14 +19,8 @@ using osu.Game.Screens.Charts;
|
||||
using osu.Game.Screens.Direct;
|
||||
using osu.Game.Screens.Edit;
|
||||
using osu.Game.Screens.Multiplayer;
|
||||
using OpenTK;
|
||||
using osu.Game.Screens.Select;
|
||||
using osu.Game.Screens.Tournament;
|
||||
using osu.Framework.Input;
|
||||
using OpenTK.Input;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace osu.Game.Screens.Menu
|
||||
{
|
||||
@ -75,10 +72,15 @@ namespace osu.Game.Screens.Menu
|
||||
if (!menuMusic)
|
||||
{
|
||||
trackManager = game.Audio.Track;
|
||||
List<BeatmapSetInfo> choosableBeatmapSets = beatmaps.Query<BeatmapSetInfo>().ToList();
|
||||
if (choosableBeatmapSets.Count > 0)
|
||||
|
||||
var query = beatmaps.Query<BeatmapSetInfo>().Where(b => !b.DeletePending);
|
||||
int count = query.Count();
|
||||
|
||||
if (count > 0)
|
||||
{
|
||||
Beatmap = beatmaps.GetWorkingBeatmap(beatmaps.GetWithChildren<BeatmapSetInfo>(choosableBeatmapSets[RNG.Next(0, choosableBeatmapSets.Count - 1)].ID).Beatmaps[0]);
|
||||
var beatmap = query.ElementAt(RNG.Next(0, count - 1));
|
||||
beatmaps.GetChildren(beatmap, true);
|
||||
Beatmap = beatmaps.GetWorkingBeatmap(beatmap.Beatmaps[0]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -220,13 +220,11 @@ namespace osu.Game.Screens.Select
|
||||
|
||||
private BeatmapGroup createGroup(BeatmapSetInfo beatmapSet)
|
||||
{
|
||||
database.GetChildren(beatmapSet);
|
||||
beatmapSet.Beatmaps.ForEach(b =>
|
||||
foreach(var b in beatmapSet.Beatmaps)
|
||||
{
|
||||
database.GetChildren(b);
|
||||
if (b.Metadata == null)
|
||||
b.Metadata = beatmapSet.Metadata;
|
||||
});
|
||||
}
|
||||
|
||||
return new BeatmapGroup(beatmapSet, database)
|
||||
{
|
||||
|
@ -183,7 +183,7 @@ namespace osu.Game.Screens.Select
|
||||
initialAddSetsTask = new CancellationTokenSource();
|
||||
|
||||
carousel.BeatmapsChanged = beatmapsLoaded;
|
||||
carousel.Beatmaps = database.Query<BeatmapSetInfo>().Where(b => !b.DeletePending);
|
||||
carousel.Beatmaps = database.GetAllWithChildren<BeatmapSetInfo>(b => !b.DeletePending);
|
||||
}
|
||||
|
||||
private void beatmapsLoaded()
|
||||
|
Loading…
x
Reference in New Issue
Block a user