Skip to content

Commit

Permalink
PT-9356: Fix sql error - The query processor ran out of internal reso…
Browse files Browse the repository at this point in the history
…urces (#182)

fix: Fixed the query processor ran out of internal resources when export more than 200 pricelists.
fix: Fixed delete prices when delete product with pagination.
  • Loading branch information
OlegoO committed Nov 2, 2022
1 parent 87b359a commit 2d3a442
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
4 changes: 2 additions & 2 deletions VirtoCommerce.PricingModule.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29025.244
# Visual Studio Version 17
VisualStudioVersion = 17.0.32112.339
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VirtoCommerce.PricingModule.Core", "src\VirtoCommerce.PricingModule.Core\VirtoCommerce.PricingModule.Core.csproj", "{EA833691-97E4-44A3-966F-AA933A73CB3D}"
EndProject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,6 @@ protected override ExportableSearchResult FetchData(PricelistSearchCriteria sear
totalCount = pricelistSearchResult.TotalCount;
}

if (!result.IsNullOrEmpty())
{
var pricelistIds = result.Select(x => x.Id).ToArray();
var prices = _searchService.SearchPricesAsync(new PricesSearchCriteria() { PriceListIds = pricelistIds, Take = int.MaxValue }).GetAwaiter().GetResult();
foreach (var pricelist in result)
{
pricelist.Prices = prices.Results.Where(x => x.PricelistId == pricelist.Id).ToArray();
}
}

return new ExportableSearchResult()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ namespace VirtoCommerce.PricingModule.Data.Handlers
{
public class DeletePricesProductChangedEventHandler : IEventHandler<ProductChangedEvent>
{
private const int _batchSize = 100;

private readonly IPricingService _pricingService;
private readonly IPricingSearchService _pricingSearchService;

Expand All @@ -26,16 +28,28 @@ public virtual async Task Handle(ProductChangedEvent message)
{
throw new ArgumentNullException(nameof(message));
}

var deletedProductIds = message.ChangedEntries.Where(x => x.EntryState == EntryState.Deleted && x.OldEntry.Id != null)
.Select(x => x.OldEntry.Id)
.Distinct().ToArray();
if (!deletedProductIds.IsNullOrEmpty())
{
var searchResult = await _pricingSearchService.SearchPricesAsync(new PricesSearchCriteria { ProductIds = deletedProductIds, Take = int.MaxValue });
if (searchResult.Results.Any())
PriceSearchResult searchResult;
do
{
await _pricingService.DeletePricesAsync(searchResult.Results.Select(p => p.Id).ToArray());
searchResult = await _pricingSearchService.SearchPricesAsync(
new PricesSearchCriteria
{
ProductIds = deletedProductIds,
Take = _batchSize
});

if (searchResult.Results.Any())
{
await _pricingService.DeletePricesAsync(searchResult.Results.Select(p => p.Id).ToArray());
}
}
while (searchResult.TotalCount > 0);
}
}
}
Expand Down

0 comments on commit 2d3a442

Please sign in to comment.