mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Optimise SQL database store and IO
* Remove unnecessary ROWID from tables. * Set JOURNAL_MODE to MEMORY, reducing disk IO. * VACUUM databases after install/compile.
This commit is contained in:
parent
d81b9026d4
commit
5d9677dbd1
@ -127,7 +127,7 @@ namespace Wabbajack.Common
|
||||
|
||||
static HashCache()
|
||||
{
|
||||
_connectionString = String.Intern($"URI=file:{DBLocation};Pooling=True;Max Pool Size=100;");
|
||||
_connectionString = String.Intern($"URI=file:{DBLocation};Pooling=True;Max Pool Size=100; Journal Mode=Memory;");
|
||||
_conn = new SQLiteConnection(_connectionString);
|
||||
_conn.Open();
|
||||
|
||||
@ -135,7 +135,8 @@ namespace Wabbajack.Common
|
||||
cmd.CommandText = @"CREATE TABLE IF NOT EXISTS HashCache (
|
||||
Path TEXT PRIMARY KEY,
|
||||
LastModified BIGINT,
|
||||
Hash BIGINT)";
|
||||
Hash BIGINT)
|
||||
WITHOUT ROWID";
|
||||
cmd.ExecuteNonQuery();
|
||||
|
||||
|
||||
@ -182,6 +183,15 @@ namespace Wabbajack.Common
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
public static void VacuumDatabase()
|
||||
{
|
||||
using var cmd = new SQLiteCommand(_conn);
|
||||
cmd.CommandText = @"VACUUM";
|
||||
cmd.PrepareAsync();
|
||||
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
public static Hash ReadHash(this BinaryReader br)
|
||||
{
|
||||
return new(br.ReadUInt64());
|
||||
|
@ -15,7 +15,7 @@ namespace Wabbajack.Common
|
||||
|
||||
static PatchCache()
|
||||
{
|
||||
_connectionString = String.Intern($"URI=file:{DBLocation};Pooling=True;Max Pool Size=100;");
|
||||
_connectionString = String.Intern($"URI=file:{DBLocation};Pooling=True;Max Pool Size=100; Journal Mode=Memory;");
|
||||
_conn = new SQLiteConnection(_connectionString);
|
||||
_conn.Open();
|
||||
|
||||
@ -25,7 +25,8 @@ namespace Wabbajack.Common
|
||||
ToHash BIGINT,
|
||||
PatchSize BLOB,
|
||||
Patch BLOB,
|
||||
PRIMARY KEY (FromHash, ToHash))";
|
||||
PRIMARY KEY (FromHash, ToHash))
|
||||
WITHOUT ROWID";
|
||||
cmd.ExecuteNonQuery();
|
||||
|
||||
}
|
||||
@ -142,6 +143,15 @@ namespace Wabbajack.Common
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static void VacuumDatabase()
|
||||
{
|
||||
using var cmd = new SQLiteCommand(_conn);
|
||||
cmd.CommandText = @"VACUUM";
|
||||
cmd.PrepareAsync();
|
||||
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
public static void ApplyPatch(Stream input, Func<Stream> openPatchStream, Stream output)
|
||||
|
@ -177,6 +177,11 @@ namespace Wabbajack.Lib
|
||||
}
|
||||
finally
|
||||
{
|
||||
Utils.Log("Vacuuming databases");
|
||||
HashCache.VacuumDatabase();
|
||||
PatchCache.VacuumDatabase();
|
||||
VirtualFile.VacuumDatabase();
|
||||
Utils.Log("Vacuuming completed");
|
||||
_isRunning.OnNext(false);
|
||||
}
|
||||
});
|
||||
|
@ -22,14 +22,15 @@ namespace Wabbajack.VirtualFileSystem
|
||||
|
||||
static VirtualFile()
|
||||
{
|
||||
_connectionString = String.Intern($"URI=file:{DBLocation};Pooling=True;Max Pool Size=100;");
|
||||
_connectionString = String.Intern($"URI=file:{DBLocation};Pooling=True;Max Pool Size=100; Journal Mode=Memory;");
|
||||
_conn = new SQLiteConnection(_connectionString);
|
||||
_conn.Open();
|
||||
|
||||
using var cmd = new SQLiteCommand(_conn);
|
||||
cmd.CommandText = @"CREATE TABLE IF NOT EXISTS VFSCache (
|
||||
Hash BIGINT PRIMARY KEY ,
|
||||
Contents BLOB)";
|
||||
Hash BIGINT PRIMARY KEY,
|
||||
Contents BLOB)
|
||||
WITHOUT ROWID";
|
||||
cmd.ExecuteNonQuery();
|
||||
|
||||
}
|
||||
@ -273,6 +274,14 @@ namespace Wabbajack.VirtualFileSystem
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public static void VacuumDatabase()
|
||||
{
|
||||
using var cmd = new SQLiteCommand(_conn);
|
||||
cmd.CommandText = @"VACUUM";
|
||||
cmd.PrepareAsync();
|
||||
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
internal void FillFullPath()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user