Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corrige rendimiento en consultas de requests #38

Merged
merged 1 commit into from
Oct 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ public GetApiRequestByIdQueryHandler(IApplicationDbContext applicationDbContext)
_applicationDbContext = applicationDbContext;
}

public async Task<ApiRequest?> Handle(GetApiRequestByIdQuery request, CancellationToken cancellationToken)
public Task<ApiRequest?> Handle(GetApiRequestByIdQuery request, CancellationToken cancellationToken)
{
return await _applicationDbContext.Requests.AsNoTracking()
// Hay un error o bug que afecta el rendimiento de la consulta se hace utilizando los metodos asincronos
// Leer: https://github.com/dotnet/efcore/issues/18221 y https://github.com/dotnet/SqlClient/issues/245 y https://github.com/dotnet/SqlClient/issues/593
// Todo: Convertir a async cuando EF Core libere una una version que corrija el rendimiento
return Task.FromResult(_applicationDbContext.Requests.AsNoTracking()
.Include(m => m.Response)
.FirstOrDefaultAsync(m => m.Id == request.ApiRequestId && m.SubscriptionKey == request.SubscriptionKey, cancellationToken);
.FirstOrDefault(m => m.Id == request.ApiRequestId && m.SubscriptionKey == request.SubscriptionKey));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@ public GetApiRequestsQueryHandler(IApplicationDbContext applicationDbContext)
_applicationDbContext = applicationDbContext;
}

public async Task<IEnumerable<ApiRequest>> Handle(GetApiRequestsQuery request, CancellationToken cancellationToken)
public Task<IEnumerable<ApiRequest>> Handle(GetApiRequestsQuery request, CancellationToken cancellationToken)
{
return await _applicationDbContext.Requests.AsNoTracking()
// Hay un error o bug que afecta el rendimiento de la consulta se hace utilizando los metodos asincronos
// Leer: https://github.com/dotnet/efcore/issues/18221 y https://github.com/dotnet/SqlClient/issues/245 y https://github.com/dotnet/SqlClient/issues/593
// Todo: Convertir a async cuando EF Core libere una una version que corrija el rendimiento
return Task.FromResult<IEnumerable<ApiRequest>>(_applicationDbContext.Requests.AsNoTracking()
.Include(m => m.Response)
.Where(m => EF.Functions.DateDiffDay(m.DateCreated, request.StartDate.ToDateTime(TimeOnly.MinValue)) >= 0 &&
EF.Functions.DateDiffDay(m.DateCreated, request.EndDate.ToDateTime(TimeOnly.MaxValue)) <= 0 &&
m.SubscriptionKey == request.SubscriptionKey)
.OrderBy(m => m.DateCreated)
.ToListAsync(cancellationToken);
.ToList());
}
}
}