Use async transactions for AddSwitch

This commit is contained in:
Ske 2020-06-13 19:14:42 +02:00
parent 37b99f9521
commit 767a37e637

View File

@ -236,7 +236,7 @@ namespace PluralKit.Core {
{ {
// Use a transaction here since we're doing multiple executed commands in one // Use a transaction here since we're doing multiple executed commands in one
await using var conn = await _conn.Obtain(); await using var conn = await _conn.Obtain();
using var tx = await conn.BeginTransactionAsync(); await using var tx = await conn.BeginTransactionAsync();
// First, we insert the switch itself // First, we insert the switch itself
var sw = await conn.QuerySingleAsync<PKSwitch>("insert into switches(system) values (@System) returning *", var sw = await conn.QuerySingleAsync<PKSwitch>("insert into switches(system) values (@System) returning *",
@ -252,7 +252,7 @@ namespace PluralKit.Core {
} }
// Finally we commit the tx, since the using block will otherwise rollback it // Finally we commit the tx, since the using block will otherwise rollback it
tx.Commit(); await tx.CommitAsync();
_logger.Information("Registered switch {Switch} in system {System} with members {@Members}", sw.Id, system.Id, members.Select(m => m.Id)); _logger.Information("Registered switch {Switch} in system {System} with members {@Members}", sw.Id, system.Id, members.Select(m => m.Id));
} }