Skip to content

Commit

Permalink
Improved AddRange for MessageRepositorySQLite - now works as a transa…
Browse files Browse the repository at this point in the history
…ction
  • Loading branch information
GlitchedPolygons committed Aug 7, 2019
1 parent f7e3c9e commit af6e0b4
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Services/Convos/MessageRepositorySQLite.cs
Expand Up @@ -300,6 +300,7 @@ public async Task<bool> AddRange(IEnumerable<Message> 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
{
Expand All @@ -308,7 +309,12 @@ public async Task<bool> AddRange(IEnumerable<Message> messages)
SenderName = m.SenderName,
TimestampUTC = m.TimestampUTC.ToUnixTimeMilliseconds(),
Body = m.Body,
})) > 0;
}), t) > 0;

if (success)
{
t.Commit();
}
}

return success;
Expand Down

0 comments on commit af6e0b4

Please sign in to comment.