From af6e0b4fbb392b5114a141263f274d1789e4a551 Mon Sep 17 00:00:00 2001 From: Raphael Beck Date: Wed, 7 Aug 2019 12:42:56 +0200 Subject: [PATCH] Improved AddRange for MessageRepositorySQLite - now works as a transaction --- src/Services/Convos/MessageRepositorySQLite.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Services/Convos/MessageRepositorySQLite.cs b/src/Services/Convos/MessageRepositorySQLite.cs index 4016a1f..05d0bae 100644 --- a/src/Services/Convos/MessageRepositorySQLite.cs +++ b/src/Services/Convos/MessageRepositorySQLite.cs @@ -300,6 +300,7 @@ public async Task AddRange(IEnumerable messages) string sql = $"INSERT OR IGNORE INTO \"{tableName}\" VALUES (@Id, @SenderId, @SenderName, @TimestampUTC, @Body)"; using (var dbcon = OpenConnection()) + using (var t = dbcon.BeginTransaction()) { success = await dbcon.ExecuteAsync(sql, messages.Where(m => m.Id.NotNullNotEmpty()).Select(m => new { @@ -308,7 +309,12 @@ public async Task AddRange(IEnumerable messages) SenderName = m.SenderName, TimestampUTC = m.TimestampUTC.ToUnixTimeMilliseconds(), Body = m.Body, - })) > 0; + }), t) > 0; + + if (success) + { + t.Commit(); + } } return success;