Fix concurrent

This commit is contained in:
2025-08-14 18:31:44 +07:00
parent 0a2b7aa335
commit cfb04e9dc9
4 changed files with 71 additions and 74 deletions

View File

@@ -137,14 +137,24 @@ public class PostgreSqlBotRepository : IBotRepository
public async Task<IEnumerable<Bot>> GetBotsByIdsAsync(IEnumerable<Guid> identifiers)
{
var entities = await _context.Bots
.AsNoTracking()
.Include(m => m.User)
.Where(b => identifiers.Contains(b.Identifier))
.ToListAsync()
.ConfigureAwait(false);
try
{
await PostgreSqlConnectionHelper.EnsureConnectionOpenAsync(_context);
return PostgreSqlMappers.Map(entities);
var entities = await _context.Bots
.AsNoTracking()
.Include(m => m.User)
.Where(b => identifiers.Contains(b.Identifier))
.ToListAsync()
.ConfigureAwait(false);
return PostgreSqlMappers.Map(entities);
}
finally
{
// Always ensure the connection is closed after the operation
await PostgreSqlConnectionHelper.SafeCloseConnectionAsync(_context);
}
}
public async Task<(IEnumerable<Bot> Bots, int TotalCount)> GetBotsPaginatedAsync(