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

@ -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(() =>
{