From 7f317a2b18c92e7be80eb866ee643b50b3fae32f Mon Sep 17 00:00:00 2001 From: Jon Kazama Date: Wed, 13 May 2026 20:31:43 +0200 Subject: [PATCH] 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. --- HellionChat/MessageStore.cs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/HellionChat/MessageStore.cs b/HellionChat/MessageStore.cs index 9aa3bfe..fd4378d 100644 --- a/HellionChat/MessageStore.cs +++ b/HellionChat/MessageStore.cs @@ -198,22 +198,31 @@ internal class MessageStore : IDisposable Connection.Dispose(); } - private SqliteConnection Connect() + private static string BuildConnectionString(string dbPath) { var uriBuilder = new SqliteConnectionStringBuilder { - DataSource = DbPath, + DataSource = dbPath, DefaultTimeout = 5, Pooling = false, Mode = SqliteOpenMode.ReadWriteCreate, }; + return uriBuilder.ToString(); + } - var conn = new SqliteConnection(uriBuilder.ToString()); - conn.Open(); + private void ApplyPragmas(SqliteConnection conn) + { conn.Execute(@"PRAGMA journal_mode=WAL;"); conn.Execute(@"PRAGMA synchronous=NORMAL;"); if (_platformUtil.IsWine) conn.Execute(@"PRAGMA cache_size = 32768;"); + } + + private SqliteConnection Connect() + { + var conn = new SqliteConnection(BuildConnectionString(DbPath)); + conn.Open(); + ApplyPragmas(conn); return conn; }