fix: 修复规格模板查询并发DbContext异常
All checks were successful
Build and Deploy TenantApi / build-and-deploy (push) Successful in 44s
All checks were successful
Build and Deploy TenantApi / build-and-deploy (push) Successful in 44s
This commit is contained in:
@@ -61,12 +61,15 @@ public sealed class CopyProductSpecTemplateCommandHandler(
|
|||||||
await productRepository.SaveChangesAsync(cancellationToken);
|
await productRepository.SaveChangesAsync(cancellationToken);
|
||||||
|
|
||||||
// 4. 复制选项与关联商品。
|
// 4. 复制选项与关联商品。
|
||||||
var sourceOptionsTask = productRepository.GetSpecTemplateOptionsByTemplateIdsAsync([source.Id], tenantId, cancellationToken);
|
var sourceOptions = await productRepository.GetSpecTemplateOptionsByTemplateIdsAsync(
|
||||||
var sourceRelationsTask = productRepository.GetSpecTemplateProductsByTemplateIdsAsync([source.Id], tenantId, request.StoreId, cancellationToken);
|
[source.Id],
|
||||||
await Task.WhenAll(sourceOptionsTask, sourceRelationsTask);
|
tenantId,
|
||||||
|
cancellationToken);
|
||||||
var sourceOptions = await sourceOptionsTask;
|
var sourceRelations = await productRepository.GetSpecTemplateProductsByTemplateIdsAsync(
|
||||||
var sourceRelations = await sourceRelationsTask;
|
[source.Id],
|
||||||
|
tenantId,
|
||||||
|
request.StoreId,
|
||||||
|
cancellationToken);
|
||||||
|
|
||||||
if (sourceOptions.Count > 0)
|
if (sourceOptions.Count > 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -55,15 +55,21 @@ public sealed class GetProductSpecTemplateListQueryHandler(
|
|||||||
}
|
}
|
||||||
|
|
||||||
var templateIds = filteredList.Select(item => item.Id).ToList();
|
var templateIds = filteredList.Select(item => item.Id).ToList();
|
||||||
var optionsTask = productRepository.GetSpecTemplateOptionsByTemplateIdsAsync(templateIds, tenantId, cancellationToken);
|
var options = await productRepository.GetSpecTemplateOptionsByTemplateIdsAsync(
|
||||||
var relationsTask = productRepository.GetSpecTemplateProductsByTemplateIdsAsync(templateIds, tenantId, request.StoreId, cancellationToken);
|
templateIds,
|
||||||
await Task.WhenAll(optionsTask, relationsTask);
|
tenantId,
|
||||||
|
cancellationToken);
|
||||||
|
var relations = await productRepository.GetSpecTemplateProductsByTemplateIdsAsync(
|
||||||
|
templateIds,
|
||||||
|
tenantId,
|
||||||
|
request.StoreId,
|
||||||
|
cancellationToken);
|
||||||
|
|
||||||
// 4. 构建查找字典并映射 DTO。
|
// 4. 构建查找字典并映射 DTO。
|
||||||
var optionsLookup = (await optionsTask)
|
var optionsLookup = options
|
||||||
.GroupBy(x => x.TemplateId)
|
.GroupBy(x => x.TemplateId)
|
||||||
.ToDictionary(group => group.Key, group => group.OrderBy(item => item.SortOrder).ThenBy(item => item.Id).ToList());
|
.ToDictionary(group => group.Key, group => group.OrderBy(item => item.SortOrder).ThenBy(item => item.Id).ToList());
|
||||||
var productIdsLookup = (await relationsTask)
|
var productIdsLookup = relations
|
||||||
.GroupBy(x => x.TemplateId)
|
.GroupBy(x => x.TemplateId)
|
||||||
.ToDictionary(group => group.Key, group => group.Select(item => item.ProductId).ToList());
|
.ToDictionary(group => group.Key, group => group.Select(item => item.ProductId).ToList());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user