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

Improve performance #80

Merged
merged 2 commits into from
Mar 27, 2020
Merged
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 @@ -37,19 +37,18 @@ public PricingSearchServiceImpl(Func<IPricingRepository> repositoryFactory, ICat
{
var result = new PricingSearchResult<coreModel.Price>();

ICollection<CatalogProduct> products;

using (var repository = _repositoryFactory())
{
repository.DisableChangesTracking();

var query = GetPricesQuery(repository, criteria, out products);
var query = GetPricesQuery(repository, criteria, out _);

var sortInfos = criteria.SortInfos;
if (sortInfos.IsNullOrEmpty())
{
sortInfos = new[] { new SortInfo { SortColumn = ReflectionUtility.GetPropertyName<coreModel.Price>(x => x.List) } };
}

//Try to replace sorting columns names
TryTransformSortingInfoColumnNames(_pricesSortingAliases, sortInfos);

Expand All @@ -67,10 +66,11 @@ public PricingSearchServiceImpl(Func<IPricingRepository> repositoryFactory, ICat
query = query.Skip(criteria.Skip).Take(criteria.Take);
}

var pricesIds = query.Select(x => x.Id).ToList();
result.Results = _pricingService.GetPricesById(pricesIds.ToArray())
.OrderBy(x => pricesIds.IndexOf(x.Id))
.ToList();
var ids = query.Select(x => x.Id).ToList();

result.Results = _pricingService.GetPricesById(ids.ToArray())
.OrderBy(x => ids.IndexOf(x.Id))
.ToList();
}

return result;
Expand All @@ -86,6 +86,8 @@ public PricingSearchServiceImpl(Func<IPricingRepository> repositoryFactory, ICat

var query = GetPricelistsQuery(repository, criteria);

result.TotalCount = query.Count();

var sortInfos = criteria.SortInfos;
if (sortInfos.IsNullOrEmpty())
{
Expand All @@ -94,13 +96,17 @@ public PricingSearchServiceImpl(Func<IPricingRepository> repositoryFactory, ICat

query = query.OrderBySortInfos(sortInfos).ThenBy(x => x.Id);

result.TotalCount = query.Count();
query = query.Skip(criteria.Skip).Take(criteria.Take);
var ids = query
.Skip(criteria.Skip)
.Take(criteria.Take)
.Select(x => x.Id)
.ToList();

var pricelistsIds = query.Select(x => x.Id).ToList();
result.Results = _pricingService.GetPricelistsById(pricelistsIds.ToArray())
.OrderBy(x => pricelistsIds.IndexOf(x.Id)).ToList();
result.Results = _pricingService.GetPricelistsById(ids.ToArray())
.OrderBy(x => ids.IndexOf(x.Id))
.ToList();
}

return result;
}

Expand All @@ -114,6 +120,8 @@ public PricingSearchServiceImpl(Func<IPricingRepository> repositoryFactory, ICat

var query = GetPricelistAssignmentsQuery(repository, criteria);

result.TotalCount = query.Count();

var sortInfos = criteria.SortInfos;
if (sortInfos.IsNullOrEmpty())
{
Expand All @@ -122,17 +130,20 @@ public PricingSearchServiceImpl(Func<IPricingRepository> repositoryFactory, ICat

query = query.OrderBySortInfos(sortInfos).ThenBy(x => x.Id);

result.TotalCount = query.Count();
query = query.Skip(criteria.Skip).Take(criteria.Take);
var ids = query
.Skip(criteria.Skip)
.Take(criteria.Take)
.Select(x => x.Id)
.ToList();

var pricelistAssignmentsIds = query.Select(x => x.Id).ToList();
result.Results = _pricingService.GetPricelistAssignmentsById(pricelistAssignmentsIds.ToArray())
.OrderBy(x => pricelistAssignmentsIds.IndexOf(x.Id))
.ToList();
result.Results = _pricingService.GetPricelistAssignmentsById(ids.ToArray())
.OrderBy(x => ids.IndexOf(x.Id))
.ToList();
}

return result;
}

#endregion


Expand Down Expand Up @@ -162,9 +173,11 @@ protected virtual IQueryable<PriceEntity> GetPricesQuery(IPricingRepository repo
Sort = criteria.Sort.Replace("product.", string.Empty),
ResponseGroup = SearchResponseGroup.WithProducts,
};

var catalogSearchResult = _catalogSearchService.Search(catalogSearchCriteria);

var productIds = catalogSearchResult.Products.Select(x => x.Id).ToArray();

//preserve resulting products for future assignment to prices
products = catalogSearchResult.Products;

Expand Down Expand Up @@ -230,8 +243,5 @@ private static void TryTransformSortingInfoColumnNames(IDictionary<string, strin
}
}
}


}
}