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 @@ public void Delete(BeatmapSetInfo beatmapSet)
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 @@ public void Undelete(BeatmapSetInfo beatmapSet)
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 @@ private void checkMigrations()
{
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 @@ public FileInfo Add(Stream data)
{
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 @@ public FileInfo Add(Stream data)
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 @@ public void Reference(IEnumerable<FileInfo> files)
});
}
public void Dereference(IEnumerable<FileInfo> files)
public void Dereference(params FileInfo[] files)
{
Connection.RunInTransaction(() =>
{

View File

@ -62,7 +62,7 @@ protected override void Prepare(bool reset = false)
{
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>