mirror of
https://github.com/osukey/osukey.git
synced 2025-07-02 08:49:59 +09: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:
@ -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(() =>
|
||||
{
|
||||
|
Reference in New Issue
Block a user