From c1071c916affa2f1b8f6fd234ca9ea3ce073f649 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kriszti=C3=A1n=20N=C3=A9meth?= Date: Mon, 29 Apr 2024 12:35:54 +0200 Subject: [PATCH 1/2] Waiting for numeric order result --- .../Services/FieldsOnlyDisplayManager.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Modules/OrchardCore.Commerce.ContentFields/Services/FieldsOnlyDisplayManager.cs b/src/Modules/OrchardCore.Commerce.ContentFields/Services/FieldsOnlyDisplayManager.cs index cc44a424f..40521f2b3 100644 --- a/src/Modules/OrchardCore.Commerce.ContentFields/Services/FieldsOnlyDisplayManager.cs +++ b/src/Modules/OrchardCore.Commerce.ContentFields/Services/FieldsOnlyDisplayManager.cs @@ -39,16 +39,18 @@ public async Task> GetFieldShapeTypesAsync( string displayType = CommonContentDisplayTypes.Detail) { var typeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(contentItem.ContentType); - return typeDefinition + + return (await typeDefinition .Parts .SelectMany(part => - part.PartDefinition.Fields.Select(field => new + part.PartDefinition.Fields.Select(async field => new { PartName = part.Name, FieldName = field.Name, - PartOrder = GetNumericOrderAsync(part), + PartOrder = await GetNumericOrderAsync(part), FieldOrder = GetNumericOrder(field), })) + .AwaitEachAsync(async fieldShapeData => await fieldShapeData)) .OrderBy(item => item.PartOrder) .ThenBy(item => item.FieldOrder) .Select(item => $"{contentItem.ContentType}_{displayType}__{item.PartName}__{item.FieldName}"); From 6e0fee9b721ea9f9d4741549de5404e5aa6468e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kriszti=C3=A1n=20N=C3=A9meth?= Date: Mon, 29 Apr 2024 13:25:49 +0200 Subject: [PATCH 2/2] Refactoring to comply with VSTHRD003 #VSTHRD003: Avoid awaiting or returning a Task representing work that was not started within your context as that can lead to deadlocks. --- .../Services/FieldsOnlyDisplayManager.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Modules/OrchardCore.Commerce.ContentFields/Services/FieldsOnlyDisplayManager.cs b/src/Modules/OrchardCore.Commerce.ContentFields/Services/FieldsOnlyDisplayManager.cs index 40521f2b3..8465ce2a3 100644 --- a/src/Modules/OrchardCore.Commerce.ContentFields/Services/FieldsOnlyDisplayManager.cs +++ b/src/Modules/OrchardCore.Commerce.ContentFields/Services/FieldsOnlyDisplayManager.cs @@ -40,17 +40,22 @@ public async Task> GetFieldShapeTypesAsync( { var typeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(contentItem.ContentType); - return (await typeDefinition + var partsOrders = new Dictionary(); + foreach (var part in typeDefinition.Parts) + { + partsOrders.Add(part.Name, await GetNumericOrderAsync(part)); + } + + return typeDefinition .Parts .SelectMany(part => - part.PartDefinition.Fields.Select(async field => new + part.PartDefinition.Fields.Select(field => new { PartName = part.Name, FieldName = field.Name, - PartOrder = await GetNumericOrderAsync(part), + PartOrder = partsOrders[part.Name], FieldOrder = GetNumericOrder(field), })) - .AwaitEachAsync(async fieldShapeData => await fieldShapeData)) .OrderBy(item => item.PartOrder) .ThenBy(item => item.FieldOrder) .Select(item => $"{contentItem.ContentType}_{displayType}__{item.PartName}__{item.FieldName}");