Posted on 10/07/2015 12:21:16
Hi Nicolai,
After some more optimizations to the function, where we are gone from a processing time on 5 minutes to 60 ms.
Here are the updated function from the assortment navigation provider (we now use a dictionary to store the groups to have a much faster lookup and have high-lighted the most important changes):
Private Function GetGroupsTreeFromAssortments(ByVal assortments As IEnumerable(Of String), ByVal includeParentGroups As Boolean) As List(Of String)
Dim assortmentGroups As New Dictionary(Of String, Group)()
For Each id As String In assortments.Distinct()
For Each assortmentRelation As AssortmentRelation In assortmentRelation.GetAssortmentRelationsByAssortment(id)
If assortmentRelation.Type = eCommerce.Assortments.AssortmentRelation.RelationType.Group Then
Dim groupRelation As AssortmentGroupRelation = CType(assortmentRelation, AssortmentGroupRelation)
If Not assortmentGroups.ContainsKey(groupRelation.GroupID) Then
assortmentGroups.Add(groupRelation.GroupID, groupRelation.Group)
End If
ElseIf assortmentRelation.Type = eCommerce.Assortments.AssortmentRelation.RelationType.Product Then
Dim productRelation As AssortmentProductRelation = CType(assortmentRelation, AssortmentProductRelation)
Dim productKey As String = NavigationCache.Current.GetProductCacheKey(productRelation.ProductID, productRelation.ProductVariantID)
Dim groups As List(Of String) = Nothing
If NavigationCache.Current.ProductGroupsCache.TryGetValue(productKey, groups) Then
If Not IsNothing(groups) Then
For Each group As String In groups
If Not assortmentGroups.ContainsKey(group) Then
Dim ecomGroup As eCommerce.Products.Group = eCommerce.Products.Group.GetGroupByID(group)
If Not IsNothing(ecomGroup) Then
assortmentGroups.Add(group, ecomGroup)
End If
End If
Next
End If
End If
'Else
' Dim shopRelation As AssortmentShopRelation = CType(assortmentRelation, AssortmentShopRelation)
' For Each group As Group In shopRelation.Shop.Groups
' If Not assortmentGroups.ContainsById(group.ID) Then
' assortmentGroups.Add(group)
' End If
' Next
End If
Next
Next
If includeParentGroups Then
Dim parentHierarchicalGroups As New Dictionary(Of String, Group)()
For Each group As Group In assortmentGroups.Values
For Each parent As Group In GetParentGroups(group)
If Not parentHierarchicalGroups.ContainsKey(parent.ID) Then
parentHierarchicalGroups.Add(parent.ID, parent)
End If
Next
Next
For Each group As Group In parentHierarchicalGroups.Values
If Not assortmentGroups.ContainsKey(group.ID) Then
assortmentGroups.Add(group.ID, group)
End If
Next
End If
Return assortmentGroups.Select(Function(group) group.Key).ToList()
End Function
Best regards, Anders