From 67175419a91367e1784524fd8ad9b7908e5ad59d Mon Sep 17 00:00:00 2001 From: Jon Kazama Date: Wed, 13 May 2026 19:20:55 +0200 Subject: [PATCH] refactor(messagestore): extract ReadMessageRow as shared deserialiser Pure deserialisation helper that pulls one row from the current reader position into a Message. The MessageEnumerator load path delegates to it, and the upcoming FTS-join LoadByGuids (Task 4.3) will share the same code so both stay in lockstep when the column layout shifts. Pre-step for v1.4.8 H2 FTS5 full-text search. --- HellionChat/MessageStore.cs | 68 ++++++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 28 deletions(-) diff --git a/HellionChat/MessageStore.cs b/HellionChat/MessageStore.cs index 8a23567..a1e1851 100644 --- a/HellionChat/MessageStore.cs +++ b/HellionChat/MessageStore.cs @@ -136,6 +136,43 @@ internal class MessageStore : IDisposable ) ); + // Pure deserialisation of one messages-row at the reader's current position. + // Shared between the MessageEnumerator load path and the upcoming v1.4.8 + // LoadByGuids FTS-join path so both stay in lockstep when the column layout + // moves. Throws on row-level errors; the caller decides whether to skip+log + // (enumerator) or fail-fast (bulk lookup). + internal static Message ReadMessageRow(DbDataReader reader) + { + return new Message( + reader.GetGuid(0), + (ulong)reader.GetInt64(1), + (ulong)reader.GetInt64(2), + DateTimeOffset.FromUnixTimeMilliseconds(reader.GetInt64(3)), + new ChatCode( + (byte)reader.GetInt32(4), + (byte)reader.GetInt32(5), + (byte)reader.GetInt32(6) + ), + MessagePackSerializer.Deserialize>( + reader.GetFieldValue(7), + MsgPackOptions + ), + MessagePackSerializer.Deserialize>( + reader.GetFieldValue(8), + MsgPackOptions + ), + MessagePackSerializer.Deserialize( + reader.GetFieldValue(9), + MsgPackOptions + ), + MessagePackSerializer.Deserialize( + reader.GetFieldValue(10), + MsgPackOptions + ), + reader.GetGuid(11) + ); + } + private readonly IPlatformUtil _platformUtil; private readonly IPluginLogProxy _logger; @@ -816,35 +853,10 @@ internal class MessageEnumerator(DbDataReader reader, IPluginLogProxy logger) Message msg; try { + // GetGuid up-front so we have an id for the failure log even + // when the rest of the deserialisation throws downstream. id = reader.GetGuid(0); - msg = new Message( - id, - (ulong)reader.GetInt64(1), - (ulong)reader.GetInt64(2), - DateTimeOffset.FromUnixTimeMilliseconds(reader.GetInt64(3)), - new ChatCode( - (byte)reader.GetInt32(4), - (byte)reader.GetInt32(5), - (byte)reader.GetInt32(6) - ), - MessagePackSerializer.Deserialize>( - reader.GetFieldValue(7), - MessageStore.MsgPackOptions - ), - MessagePackSerializer.Deserialize>( - reader.GetFieldValue(8), - MessageStore.MsgPackOptions - ), - MessagePackSerializer.Deserialize( - reader.GetFieldValue(9), - MessageStore.MsgPackOptions - ), - MessagePackSerializer.Deserialize( - reader.GetFieldValue(10), - MessageStore.MsgPackOptions - ), - reader.GetGuid(11) - ); + msg = MessageStore.ReadMessageRow(reader); } catch (Exception e) {