From 4e1922c556dd59aaa4b1dba352b250d9d55d0006 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 25 Oct 2017 17:03:10 +0900 Subject: [PATCH] Fix query methods not using IQueryable/Expressions No database-level where clauses were being used in many cases they should be. --- osu.Game/Beatmaps/BeatmapManager.cs | 9 +++++---- osu.Game/Beatmaps/BeatmapStore.cs | 5 ++--- osu.Game/Input/KeyBindingStore.cs | 4 ++-- osu.Game/Rulesets/RulesetStore.cs | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/osu.Game/Beatmaps/BeatmapManager.cs b/osu.Game/Beatmaps/BeatmapManager.cs index 7d94f56769..3bf33eaff9 100644 --- a/osu.Game/Beatmaps/BeatmapManager.cs +++ b/osu.Game/Beatmaps/BeatmapManager.cs @@ -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 Microsoft.EntityFrameworkCore; @@ -378,7 +379,7 @@ namespace osu.Game.Beatmaps /// /// The query. /// The first result for the provided query, or null if no results were found. - public BeatmapSetInfo QueryBeatmapSet(Func query) => beatmaps.BeatmapSets.FirstOrDefault(query); + public BeatmapSetInfo QueryBeatmapSet(Expression> query) => beatmaps.BeatmapSets.FirstOrDefault(query); /// /// Refresh an existing instance of a from the store. @@ -392,21 +393,21 @@ namespace osu.Game.Beatmaps /// /// The query. /// Results from the provided query. - public List QueryBeatmapSets(Func query) => beatmaps.BeatmapSets.Where(query).ToList(); + public List QueryBeatmapSets(Expression> query) => beatmaps.BeatmapSets.Where(query).ToList(); /// /// Perform a lookup query on available s. /// /// The query. /// The first result for the provided query, or null if no results were found. - public BeatmapInfo QueryBeatmap(Func query) => beatmaps.Beatmaps.FirstOrDefault(query); + public BeatmapInfo QueryBeatmap(Expression> query) => beatmaps.Beatmaps.FirstOrDefault(query); /// /// Perform a lookup query on available s. /// /// The query. /// Results from the provided query. - public List QueryBeatmaps(Func query) => beatmaps.Beatmaps.Where(query).ToList(); + public List QueryBeatmaps(Expression> query) => beatmaps.Beatmaps.Where(query).ToList(); /// /// Creates an from a valid storage path. diff --git a/osu.Game/Beatmaps/BeatmapStore.cs b/osu.Game/Beatmaps/BeatmapStore.cs index 2e6efee0aa..951177c664 100644 --- a/osu.Game/Beatmaps/BeatmapStore.cs +++ b/osu.Game/Beatmaps/BeatmapStore.cs @@ -2,7 +2,6 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System; -using System.Collections.Generic; using System.Linq; using Microsoft.EntityFrameworkCore; using osu.Game.Database; @@ -136,14 +135,14 @@ namespace osu.Game.Beatmaps context.SaveChanges(); } - public IEnumerable BeatmapSets => GetContext().BeatmapSetInfo + public IQueryable BeatmapSets => GetContext().BeatmapSetInfo .Include(s => s.Metadata) .Include(s => s.Beatmaps).ThenInclude(s => s.Ruleset) .Include(s => s.Beatmaps).ThenInclude(b => b.BaseDifficulty) .Include(s => s.Beatmaps).ThenInclude(b => b.Metadata) .Include(s => s.Files).ThenInclude(f => f.FileInfo); - public IEnumerable Beatmaps => GetContext().BeatmapInfo + public IQueryable Beatmaps => GetContext().BeatmapInfo .Include(b => b.BeatmapSet).ThenInclude(s => s.Metadata) .Include(b => b.Metadata) .Include(b => b.Ruleset) diff --git a/osu.Game/Input/KeyBindingStore.cs b/osu.Game/Input/KeyBindingStore.cs index 53309fc72d..c7da9a150d 100644 --- a/osu.Game/Input/KeyBindingStore.cs +++ b/osu.Game/Input/KeyBindingStore.cs @@ -65,8 +65,8 @@ namespace osu.Game.Input /// The ruleset's internal ID. /// An optional variant. /// - public IEnumerable Query(int? rulesetId = null, int? variant = null) => - GetContext().DatabasedKeyBinding.Where(b => b.RulesetID == rulesetId && b.Variant == variant); + public IEnumerable Query(int? rulesetId = null, int? variant = null) => + GetContext().DatabasedKeyBinding.Where(b => b.RulesetID == rulesetId && b.Variant == variant).ToList(); public void Update(KeyBinding keyBinding) { diff --git a/osu.Game/Rulesets/RulesetStore.cs b/osu.Game/Rulesets/RulesetStore.cs index 4208d0edad..51b4afac98 100644 --- a/osu.Game/Rulesets/RulesetStore.cs +++ b/osu.Game/Rulesets/RulesetStore.cs @@ -41,7 +41,7 @@ namespace osu.Game.Rulesets /// /// All available rulesets. /// - public IEnumerable AvailableRulesets => GetContext().RulesetInfo.Where(r => r.Available); + public IQueryable AvailableRulesets => GetContext().RulesetInfo.Where(r => r.Available); private static Assembly currentDomain_AssemblyResolve(object sender, ResolveEventArgs args) => loaded_assemblies.Keys.FirstOrDefault(a => a.FullName == args.Name);