Do not dispose connections created by EF

This commit is contained in:
nicolas.dorier 2024-01-25 10:45:02 +09:00
parent b62985faf4
commit f97f23c8a5
No known key found for this signature in database
GPG key ID: 6618763EF09186FE

View file

@ -393,8 +393,7 @@ namespace BTCPayServer.Services
} }
else else
{ {
var conn = ctx.Database.GetDbConnection(); await connection.ExecuteAsync("INSERT INTO \"WalletObjectLinks\" VALUES (@WalletId, @AType, @AId, @BType, @BId, @Data::JSONB) ON CONFLICT DO NOTHING", links);
await conn.ExecuteAsync("INSERT INTO \"WalletObjectLinks\" VALUES (@WalletId, @AType, @AId, @BType, @BId, @Data::JSONB) ON CONFLICT DO NOTHING", links);
} }
} }
@ -700,11 +699,9 @@ namespace BTCPayServer.Services
walletObjectLinks ??= new List<WalletObjectLinkData>(); walletObjectLinks ??= new List<WalletObjectLinkData>();
var objs = walletObjects.Concat(ExtractObjectsFromLinks(walletObjectLinks).Except(walletObjects)).ToArray(); var objs = walletObjects.Concat(ExtractObjectsFromLinks(walletObjectLinks).Except(walletObjects)).ToArray();
await using var ctx = _ContextFactory.CreateContext(); await using var ctx = _ContextFactory.CreateContext();
await using var connection = ctx.Database.GetDbConnection(); var connection = ctx.Database.GetDbConnection();
await connection.OpenAsync();
await EnsureWalletObjects(ctx,connection, objs); await EnsureWalletObjects(ctx,connection, objs);
await EnsureWalletObjectLinks(ctx,connection, walletObjectLinks); await EnsureWalletObjectLinks(ctx,connection, walletObjectLinks);
await connection.CloseAsync();
} }
#nullable restore #nullable restore
} }