Skip to content

Commit

Permalink
Improved AddRange for ConvoRepositorySQLite - now works as a transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
GlitchedPolygons committed Aug 7, 2019
1 parent af6e0b4 commit ca73822
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Services/Convos/ConvoRepositorySQLite.cs
Expand Up @@ -256,6 +256,7 @@ public async Task<bool> AddRange(IEnumerable<Convo> convos)
string sql = $"INSERT INTO \"{tableName}\" VALUES (@Id, @CreatorId, @Name, @Description, @CreationTimestampUTC, @ExpirationUTC, @Participants, @BannedUsers)";

using (var dbcon = OpenConnection())
using (var t = dbcon.BeginTransaction())
{
success = await dbcon.ExecuteAsync(sql, convos.Where(c => c.Id.NotNullNotEmpty()).Select(c => new
{
Expand All @@ -267,7 +268,12 @@ public async Task<bool> AddRange(IEnumerable<Convo> convos)
ExpirationUTC = c.ExpirationUTC.ToUnixTimeMilliseconds(),
Participants = c.GetParticipantIdsCommaSeparated(),
BannedUsers = c.GetBannedUsersCommaSeparated()
})) > 0;
}), t) > 0;

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

return success;
Expand Down

0 comments on commit ca73822

Please sign in to comment.