Skip to content

Commit

Permalink
Minor queries optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
tatarincev committed May 20, 2020
1 parent 1ac9dc8 commit 79f5a57
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public virtual Task<PriceSearchResult> SearchPricesAsync(PricesSearchCriteria cr
{
var priceIds = await query.OrderBySortInfos(sortInfos).ThenBy(x => x.Id)
.Select(x => x.Id)
.AsNoTracking()
.ToArrayAsync();

var unorderedResults = await _pricingService.GetPricesByIdAsync(priceIds);
Expand Down Expand Up @@ -103,6 +104,7 @@ public virtual async Task<PricelistSearchResult> SearchPricelistsAsync(Pricelist
var pricelistIds = await query.OrderBySortInfos(sortInfos).ThenBy(x => x.Id)
.Select(x => x.Id)
.Skip(criteria.Skip).Take(criteria.Take)
.AsNoTracking()
.ToArrayAsync();
var unorderedResults = await _pricingService.GetPricelistsByIdAsync(pricelistIds);
result.Results = unorderedResults.OrderBy(x => Array.IndexOf(pricelistIds, x.Id)).ToList();
Expand Down Expand Up @@ -134,6 +136,7 @@ public virtual async Task<PricelistAssignmentSearchResult> SearchPricelistAssign
var pricelistAssignmentsIds = await query.OrderBySortInfos(sortInfos).ThenBy(x => x.Id)
.Select(x => x.Id)
.Skip(criteria.Skip).Take(criteria.Take)
.AsNoTracking()
.ToArrayAsync();
var unorderedResults = await _pricingService.GetPricelistAssignmentsByIdAsync(pricelistAssignmentsIds);
result.Results = unorderedResults.OrderBy(x => Array.IndexOf(pricelistAssignmentsIds, x.Id)).ToList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public virtual async Task<IEnumerable<Pricelist>> EvaluatePriceListsAsync(PriceE
query = query.Where(x => (x.StartDate == null || evalContext.CertainDate >= x.StartDate) && (x.EndDate == null || x.EndDate >= evalContext.CertainDate));
}

var assignments = query.ToArray();
var assignments = query.AsNoTracking().ToArray();
var assignmentsToReturn = assignments.Where(x => x.DynamicExpression == null).ToList();

foreach (var assignment in assignments.Where(x => x.DynamicExpression != null))
Expand All @@ -109,7 +109,7 @@ public virtual async Task<PricelistAssignment[]> GetAllPricelistAssignments()
{
repository.DisableChangesTracking();

return (await repository.PricelistAssignments.Include(x => x.Pricelist).ToArrayAsync()).Select(x => x.ToModel(AbstractTypeFactory<PricelistAssignment>.TryCreateInstance())).ToArray();
return (await repository.PricelistAssignments.Include(x => x.Pricelist).AsNoTracking().ToArrayAsync()).Select(x => x.ToModel(AbstractTypeFactory<PricelistAssignment>.TryCreateInstance())).ToArray();
}
}
/// <summary>
Expand Down Expand Up @@ -151,7 +151,7 @@ public virtual async Task<IEnumerable<Price>> EvaluateProductPricesAsync(PriceEv
query = query.Where(x => (x.StartDate == null || x.StartDate <= certainDate)
&& (x.EndDate == null || x.EndDate > certainDate));

var queryResult = await query.ToArrayAsync();
var queryResult = await query.AsNoTracking().ToArrayAsync();
prices = queryResult.Select(x => x.ToModel(AbstractTypeFactory<Price>.TryCreateInstance())).ToArray();
}

Expand Down

0 comments on commit 79f5a57

Please sign in to comment.