optimization sql

This commit is contained in:
Artemy
2025-07-01 15:05:49 +07:00
parent 5883f3e340
commit cdae63b223
10 changed files with 81 additions and 58 deletions
@@ -52,13 +52,13 @@ public class InviteUserController : Controller
_logger.LogInformation("Getting all active invitations by administrator");
var read = await _repository.GetAllAsync();
var result = read.Where(x => x.IsActive == true).ToList();
var result = read.Where(x => x.IsActive).ToList();
List<InvitationDto> dtos = new List<InvitationDto>();
List<InvitationResponses> dtos = new List<InvitationResponses>();
foreach (var inv in result)
{
dtos.Add(new InvitationDto(){
dtos.Add(new InvitationResponses(){
Id = inv.Id,
Description = inv.Description,
IsAdmin = inv.IsAdmin,
@@ -67,6 +67,7 @@ public class InviteUserController : Controller
CreatedAt = inv.DateCreated,
EndAt = inv.EndDate,
IsActive = inv.IsActive,
ParticipantCount = inv.Users.Count,
});
}
@@ -87,11 +88,11 @@ public class InviteUserController : Controller
_logger.LogInformation("Getting all invitations by administrator");
var read = await _repository.GetAllAsync();
List<InvitationDto> dtos = new List<InvitationDto>();
List<InvitationResponses> dtos = new List<InvitationResponses>();
foreach (var inv in read)
{
dtos.Add(new InvitationDto(){
dtos.Add(new InvitationResponses(){
Id = inv.Id,
Description = inv.Description,
IsAdmin = inv.IsAdmin,
@@ -100,6 +101,7 @@ public class InviteUserController : Controller
CreatedAt = inv.DateCreated,
EndAt = inv.EndDate,
IsActive = inv.IsActive,
ParticipantCount = inv.Users.Count,
});
}
@@ -120,18 +122,18 @@ public class InviteUserController : Controller
_logger.LogInformation("Getting invitations {id} by administrator");
var read = await _repository.FindByIdAsync(id);
var response = new InvitationDto(){
Id = read.Id,
Description = read.Description,
IsAdmin = read.IsAdmin,
MaxParticipants = read.MaxParticipants,
Code = read.Code,
CreatedAt = read.DateCreated,
EndAt = read.EndDate,
IsActive = read.IsActive,
var response = new InvitationResponses(){
Id = read.Id,
Description = read.Description,
IsAdmin = read.IsAdmin,
MaxParticipants = read.MaxParticipants,
Code = read.Code,
CreatedAt = read.DateCreated,
EndAt = read.EndDate,
IsActive = read.IsActive,
ParticipantCount = read.Users.Count,
};
return Ok(response);
}
catch (Exception e)
@@ -67,19 +67,29 @@ public static class ConfigurationProgramExtensions
public static void AddGovorDbContext(this IServiceCollection services, IConfiguration configuration)
{
var useMySql = configuration.GetValue<bool>("UseMySql"); // Получаем значение из конфигурации
var useMySql = configuration.GetValue<bool>("UseMySql");
if (useMySql)
{
services.AddDbContext<GovorDbContext>(options =>
options.UseMySql(configuration.GetConnectionString(nameof(GovorDbContext)),
new MySqlServerVersion(new Version(8, 0, 21))));
{
options
.UseMySql(
configuration.GetConnectionString(nameof(GovorDbContext)),
new MySqlServerVersion(new Version(8, 0, 21))
);
options.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
});
}
else
{
services.AddDbContext<GovorDbContext>(options =>
options.UseNpgsql(configuration.GetConnectionString(nameof(GovorDbContext))));
{
options.UseNpgsql(configuration.GetConnectionString(nameof(GovorDbContext)));
options.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
});
}
}
}