Revert "Return back DatabaseBackedStore's query and populate functions"

This reverts commit 7cf5d63cd3.
This commit is contained in:
Dean Herbert
2017-10-16 12:56:58 +09:00
parent 04e5f764a3
commit 8a0b184dd6
10 changed files with 80 additions and 120 deletions

View File

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using Ionic.Zip;
using osu.Framework.Audio.Track;
@ -259,13 +260,10 @@ namespace osu.Game.Beatmaps
/// <param name="beatmapSet">The beatmap set to delete.</param>
public void Delete(BeatmapSetInfo beatmapSet)
{
lock (beatmaps)
{
if (!beatmaps.Delete(beatmapSet)) return;
if (!beatmaps.Delete(beatmapSet)) return;
if (!beatmapSet.Protected)
files.Dereference(beatmapSet.Files.Select(f => f.FileInfo).ToArray());
}
if (!beatmapSet.Protected)
files.Dereference(beatmapSet.Files.Select(f => f.FileInfo).ToArray());
}
/// <summary>
@ -304,9 +302,6 @@ namespace osu.Game.Beatmaps
if (beatmapInfo == null || beatmapInfo == DefaultBeatmap?.BeatmapInfo)
return DefaultBeatmap;
lock (beatmaps)
beatmaps.Populate(beatmapInfo);
if (beatmapInfo.BeatmapSet == null)
throw new InvalidOperationException($@"Beatmap set {beatmapInfo.BeatmapSetInfoID} is not in the local database.");
@ -338,10 +333,7 @@ namespace osu.Game.Beatmaps
{
lock (beatmaps)
{
BeatmapSetInfo set = beatmaps.Query(query).FirstOrDefault();
if (set != null)
beatmaps.Populate(set);
BeatmapSetInfo set = beatmaps.QueryBeatmapSet(query);
return set;
}
@ -359,9 +351,9 @@ namespace osu.Game.Beatmaps
/// </summary>
/// <param name="query">The query.</param>
/// <returns>Results from the provided query.</returns>
public List<BeatmapSetInfo> QueryBeatmapSets(Func<BeatmapSetInfo, bool> query)
public List<BeatmapSetInfo> QueryBeatmapSets(Expression<Func<BeatmapSetInfo, bool>> query)
{
return beatmaps.QueryAndPopulate(query);
return beatmaps.QueryBeatmapSets(query);
}
/// <summary>
@ -371,15 +363,9 @@ namespace osu.Game.Beatmaps
/// <returns>The first result for the provided query, or null if no results were found.</returns>
public BeatmapInfo QueryBeatmap(Func<BeatmapInfo, bool> query)
{
lock (beatmaps)
{
BeatmapInfo set = beatmaps.Query(query).FirstOrDefault();
BeatmapInfo set = beatmaps.QueryBeatmap(query);
if (set != null)
beatmaps.Populate(set);
return set;
}
return set;
}
/// <summary>
@ -387,9 +373,9 @@ namespace osu.Game.Beatmaps
/// </summary>
/// <param name="query">The query.</param>
/// <returns>Results from the provided query.</returns>
public List<BeatmapInfo> QueryBeatmaps(Func<BeatmapInfo, bool> query)
public List<BeatmapInfo> QueryBeatmaps(Expression<Func<BeatmapInfo, bool>> query)
{
lock (beatmaps) return beatmaps.Query(query);
lock (beatmaps) return beatmaps.QueryBeatmaps(query);
}
/// <summary>
@ -428,7 +414,7 @@ namespace osu.Game.Beatmaps
// check if this beatmap has already been imported and exit early if so.
BeatmapSetInfo beatmapSet;
lock (beatmaps)
beatmapSet = beatmaps.QueryAndPopulate<BeatmapSetInfo>(b => b.Hash == hash).FirstOrDefault();
beatmapSet = beatmaps.QueryBeatmapSet(b => b.Hash == hash);
if (beatmapSet != null)
{
@ -492,8 +478,8 @@ namespace osu.Game.Beatmaps
beatmap.BeatmapInfo.Metadata = null;
// TODO: this should be done in a better place once we actually need to dynamically update it.
beatmap.BeatmapInfo.Ruleset = rulesets.Query<RulesetInfo>(r => r.ID == beatmap.BeatmapInfo.RulesetID).FirstOrDefault();
beatmap.BeatmapInfo.StarDifficulty = rulesets.Query<RulesetInfo>(r => r.ID == beatmap.BeatmapInfo.RulesetID).FirstOrDefault()?.CreateInstance()?.CreateDifficultyCalculator(beatmap)
beatmap.BeatmapInfo.Ruleset = rulesets.QueryRulesetInfo(r => r.ID == beatmap.BeatmapInfo.RulesetID);
beatmap.BeatmapInfo.StarDifficulty = rulesets.QueryRulesetInfo(r => r.ID == beatmap.BeatmapInfo.RulesetID)?.CreateInstance()?.CreateDifficultyCalculator(beatmap)
.Calculate() ?? 0;
beatmapSet.Beatmaps.Add(beatmap.BeatmapInfo);
@ -507,11 +493,11 @@ namespace osu.Game.Beatmaps
/// Returns a list of all usable <see cref="BeatmapSetInfo"/>s.
/// </summary>
/// <returns>A list of available <see cref="BeatmapSetInfo"/>.</returns>
public List<BeatmapSetInfo> GetAllUsableBeatmapSets(bool populate = true)
public List<BeatmapSetInfo> GetAllUsableBeatmapSets()
{
lock (beatmaps)
{
return populate ? beatmaps.QueryAndPopulate<BeatmapSetInfo>(b => !b.DeletePending) : beatmaps.Query<BeatmapSetInfo>(b => !b.DeletePending);
return beatmaps.QueryBeatmapSets(b => !b.DeletePending);
}
}