1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 11:37:28 +08:00

Optimise file lookups and other database operations

FirstOrDefault when called on a TableQuery with a predicate doesn't use table indices
This commit is contained in:
Dean Herbert 2017-08-01 17:37:21 +09:00
parent e7e822ecd5
commit 3b1166d1e6
5 changed files with 10 additions and 12 deletions

View File

@ -174,7 +174,7 @@ namespace osu.Game.Beatmaps
if (!beatmaps.Delete(beatmapSet)) return;
if (!beatmapSet.Protected)
files.Dereference(beatmapSet.Files.Select(f => f.FileInfo));
files.Dereference(beatmapSet.Files.Select(f => f.FileInfo).ToArray());
}
/// <summary>
@ -188,7 +188,7 @@ namespace osu.Game.Beatmaps
if (!beatmaps.Undelete(beatmapSet)) return;
if (!beatmapSet.Protected)
files.Reference(beatmapSet.Files.Select(f => f.FileInfo));
files.Reference(beatmapSet.Files.Select(f => f.FileInfo).ToArray());
}
/// <summary>

View File

@ -41,7 +41,7 @@ namespace osu.Game.Database
{
var storeName = GetType().Name;
var reportedVersion = Connection.Table<StoreVersion>().FirstOrDefault(s => s.StoreName == storeName) ?? new StoreVersion
var reportedVersion = Connection.Table<StoreVersion>().Where(s => s.StoreName == storeName).FirstOrDefault() ?? new StoreVersion
{
StoreName = storeName,
Version = 0

View File

@ -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.IO;
using System.Linq;
using osu.Framework.Extensions;
@ -83,10 +82,9 @@ namespace osu.Game.IO
{
string hash = data.ComputeSHA2Hash();
var info = new FileInfo { Hash = hash };
var existing = Connection.Table<FileInfo>().FirstOrDefault(f => f.Hash == info.Hash);
var existing = Connection.Table<FileInfo>().Where(f => f.Hash == hash).FirstOrDefault();
var info = existing ?? new FileInfo { Hash = hash };
if (existing != null)
{
info = existing;
@ -106,11 +104,11 @@ namespace osu.Game.IO
Connection.Insert(info);
}
Reference(new[] { info });
Reference(info);
return info;
}
public void Reference(IEnumerable<FileInfo> files)
public void Reference(params FileInfo[] files)
{
Connection.RunInTransaction(() =>
{
@ -125,7 +123,7 @@ namespace osu.Game.IO
});
}
public void Dereference(IEnumerable<FileInfo> files)
public void Dereference(params FileInfo[] files)
{
Connection.RunInTransaction(() =>
{

View File

@ -62,7 +62,7 @@ namespace osu.Game.Rulesets
{
var us = createRulesetInfo(r);
var existing = Query<RulesetInfo>().FirstOrDefault(ri => ri.InstantiationInfo == us.InstantiationInfo);
var existing = Query<RulesetInfo>().Where(ri => ri.InstantiationInfo == us.InstantiationInfo).FirstOrDefault();
if (existing == null)
Connection.Insert(us);

View File

@ -115,7 +115,7 @@
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ReplaceWithSingleCallToAny/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ReplaceWithSingleCallToCount/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ReplaceWithSingleCallToFirst/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ReplaceWithSingleCallToFirstOrDefault/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ReplaceWithSingleCallToFirstOrDefault/@EntryIndexedValue">HINT</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ReplaceWithSingleCallToLast/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ReplaceWithSingleCallToLastOrDefault/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ReplaceWithSingleCallToSingle/@EntryIndexedValue">WARNING</s:String>