refactor(messagestore): extract BuildConnectionString and ApplyPragmas helpers
Pre-step for the v1.4.8 FTS5 bulk-insert worker. The worker opens its own secondary SqliteConnection on the same db path so the WAL journal lets parallel reads/writes through, and it has to apply the exact same connection-string options and PRAGMAs as Connect() -- otherwise the worker connection drifts the moment Connect grows a new pragma. Splitting BuildConnectionString + ApplyPragmas out lets both Connect() and the upcoming OpenSecondaryConnection() share the same source of truth instead of duplicating the body. No behaviour change.
This commit is contained in:
@@ -198,22 +198,31 @@ internal class MessageStore : IDisposable
|
|||||||
Connection.Dispose();
|
Connection.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
private SqliteConnection Connect()
|
private static string BuildConnectionString(string dbPath)
|
||||||
{
|
{
|
||||||
var uriBuilder = new SqliteConnectionStringBuilder
|
var uriBuilder = new SqliteConnectionStringBuilder
|
||||||
{
|
{
|
||||||
DataSource = DbPath,
|
DataSource = dbPath,
|
||||||
DefaultTimeout = 5,
|
DefaultTimeout = 5,
|
||||||
Pooling = false,
|
Pooling = false,
|
||||||
Mode = SqliteOpenMode.ReadWriteCreate,
|
Mode = SqliteOpenMode.ReadWriteCreate,
|
||||||
};
|
};
|
||||||
|
return uriBuilder.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
var conn = new SqliteConnection(uriBuilder.ToString());
|
private void ApplyPragmas(SqliteConnection conn)
|
||||||
conn.Open();
|
{
|
||||||
conn.Execute(@"PRAGMA journal_mode=WAL;");
|
conn.Execute(@"PRAGMA journal_mode=WAL;");
|
||||||
conn.Execute(@"PRAGMA synchronous=NORMAL;");
|
conn.Execute(@"PRAGMA synchronous=NORMAL;");
|
||||||
if (_platformUtil.IsWine)
|
if (_platformUtil.IsWine)
|
||||||
conn.Execute(@"PRAGMA cache_size = 32768;");
|
conn.Execute(@"PRAGMA cache_size = 32768;");
|
||||||
|
}
|
||||||
|
|
||||||
|
private SqliteConnection Connect()
|
||||||
|
{
|
||||||
|
var conn = new SqliteConnection(BuildConnectionString(DbPath));
|
||||||
|
conn.Open();
|
||||||
|
ApplyPragmas(conn);
|
||||||
return conn;
|
return conn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user