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

clear cache #406

Merged
merged 4 commits into from
Mar 1, 2024
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
26 changes: 21 additions & 5 deletions src/VirtoCommerce.OrdersModule.Data/Services/PaymentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using VirtoCommerce.OrdersModule.Core.Services;
using VirtoCommerce.OrdersModule.Data.Model;
using VirtoCommerce.OrdersModule.Data.Repositories;
using VirtoCommerce.Platform.Caching;
using VirtoCommerce.Platform.Core.Caching;
using VirtoCommerce.Platform.Core.Common;
using VirtoCommerce.Platform.Core.Events;
Expand Down Expand Up @@ -67,26 +68,41 @@ protected virtual async Task DoBulkActionsWithOrderAggregate(IList<PaymentIn> pa
{
throw new OperationCanceledException($"{nameof(PaymentIn.OrderId)} must be set.");
}
var oderIds = payments.Select(x => x.OrderId).Distinct().ToArray();
if (oderIds.Any())
var orderIds = payments.Select(x => x.OrderId).Distinct().ToArray();
if (orderIds.Length > 0)
{
var ordersAggregates = await _customerOrderService.GetAsync(oderIds);
var ordersAggregates = await _customerOrderService.GetAsync(orderIds);
foreach (var payment in payments)
{
var orderAggregateRoot = ordersAggregates.FirstOrDefault(x => x.Id == payment.OrderId);
if (orderAggregateRoot != null)
{
orderAggregateRoot.InPayments.Remove(payment);
orderAggregateRoot.InPayments.Add(payment);
action(orderAggregateRoot, payment);
}
}
await _customerOrderService.SaveChangesAsync(ordersAggregates.ToArray());
}
ClearCache(payments);
}

protected override Task<IList<PaymentInEntity>> LoadEntities(IRepository repository, IList<string> ids, string responseGroup)
{
return ((IOrderRepository)repository).GetPaymentsByIdsAsync(ids);
}

protected override void ClearCache(IList<PaymentIn> models)
{
base.ClearCache(models);

// Clear order cache
GenericSearchCachingRegion<CustomerOrder>.ExpireRegion();

var orderIds = models.Select(x => x.OrderId).Distinct().ToArray();

foreach (var id in orderIds)
{
GenericCachingRegion<CustomerOrder>.ExpireTokenForKey(id);
}
}
}
}
Loading