mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Merge pull request #1245 from Unnoen/sqlite-db-optimisation
Optimise SQLite database store and IO.
This commit is contained in:
commit
eaa394d5f1
@ -127,7 +127,7 @@ namespace Wabbajack.Common
|
|||||||
|
|
||||||
static HashCache()
|
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 = new SQLiteConnection(_connectionString);
|
||||||
_conn.Open();
|
_conn.Open();
|
||||||
|
|
||||||
@ -135,7 +135,8 @@ namespace Wabbajack.Common
|
|||||||
cmd.CommandText = @"CREATE TABLE IF NOT EXISTS HashCache (
|
cmd.CommandText = @"CREATE TABLE IF NOT EXISTS HashCache (
|
||||||
Path TEXT PRIMARY KEY,
|
Path TEXT PRIMARY KEY,
|
||||||
LastModified BIGINT,
|
LastModified BIGINT,
|
||||||
Hash BIGINT)";
|
Hash BIGINT)
|
||||||
|
WITHOUT ROWID";
|
||||||
cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
|
|
||||||
|
|
||||||
@ -182,6 +183,15 @@ namespace Wabbajack.Common
|
|||||||
cmd.ExecuteNonQuery();
|
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)
|
public static Hash ReadHash(this BinaryReader br)
|
||||||
{
|
{
|
||||||
return new(br.ReadUInt64());
|
return new(br.ReadUInt64());
|
||||||
|
@ -15,7 +15,7 @@ namespace Wabbajack.Common
|
|||||||
|
|
||||||
static PatchCache()
|
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 = new SQLiteConnection(_connectionString);
|
||||||
_conn.Open();
|
_conn.Open();
|
||||||
|
|
||||||
@ -25,7 +25,8 @@ namespace Wabbajack.Common
|
|||||||
ToHash BIGINT,
|
ToHash BIGINT,
|
||||||
PatchSize BLOB,
|
PatchSize BLOB,
|
||||||
Patch BLOB,
|
Patch BLOB,
|
||||||
PRIMARY KEY (FromHash, ToHash))";
|
PRIMARY KEY (FromHash, ToHash))
|
||||||
|
WITHOUT ROWID";
|
||||||
cmd.ExecuteNonQuery();
|
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)
|
public static void ApplyPatch(Stream input, Func<Stream> openPatchStream, Stream output)
|
||||||
|
@ -177,6 +177,11 @@ namespace Wabbajack.Lib
|
|||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
Utils.Log("Vacuuming databases");
|
||||||
|
HashCache.VacuumDatabase();
|
||||||
|
PatchCache.VacuumDatabase();
|
||||||
|
VirtualFile.VacuumDatabase();
|
||||||
|
Utils.Log("Vacuuming completed");
|
||||||
_isRunning.OnNext(false);
|
_isRunning.OnNext(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -22,14 +22,15 @@ namespace Wabbajack.VirtualFileSystem
|
|||||||
|
|
||||||
static VirtualFile()
|
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 = new SQLiteConnection(_connectionString);
|
||||||
_conn.Open();
|
_conn.Open();
|
||||||
|
|
||||||
using var cmd = new SQLiteCommand(_conn);
|
using var cmd = new SQLiteCommand(_conn);
|
||||||
cmd.CommandText = @"CREATE TABLE IF NOT EXISTS VFSCache (
|
cmd.CommandText = @"CREATE TABLE IF NOT EXISTS VFSCache (
|
||||||
Hash BIGINT PRIMARY KEY ,
|
Hash BIGINT PRIMARY KEY,
|
||||||
Contents BLOB)";
|
Contents BLOB)
|
||||||
|
WITHOUT ROWID";
|
||||||
cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -273,6 +274,14 @@ namespace Wabbajack.VirtualFileSystem
|
|||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public static void VacuumDatabase()
|
||||||
|
{
|
||||||
|
using var cmd = new SQLiteCommand(_conn);
|
||||||
|
cmd.CommandText = @"VACUUM";
|
||||||
|
cmd.PrepareAsync();
|
||||||
|
|
||||||
|
cmd.ExecuteNonQuery();
|
||||||
|
}
|
||||||
|
|
||||||
internal void FillFullPath()
|
internal void FillFullPath()
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user