November Happy Hour will be moved to Thursday December 5th.

RemoveAssociation really slow after recent update

Vote:
 

I have recently upgraded to Commerce 13.30.0 and ever since our scheduled job that imports products is running incredibly slow. Before the update it would run in minutes. Now it will take hours. 

This scheduled job pulls in products from an external REST service on our end.

I have narrowed it down to the  "_associationRepository.RemoveAssociation(association)" call of the following function:

public async Task<List<Association>> Import(IServiceLayerApi serviceLayerApi, KitContent kitContent)
        {
            var bomInfo = await GetBomInformationRecursive(serviceLayerApi, kitContent.Code);

            var associations = bomInfo
                .Select(x => CreateAssociation(kitContent.ContentLink, x))
                .Where(x => x != null)
                .ToList();

            var existing = _associationRepository.GetAssociations(kitContent.ContentLink).ToArray();
            foreach (var association in existing)
            {
                _associationRepository.RemoveAssociation(association);
            }
            _associationRepository.UpdateAssociations(associations);

            return associations;
        }

When i remove the foreach loop with the RemoveAssociation call the scheduled job goes back to taking only a minute.

Is there something that changed from Commerce 13.29 to 13.30 that would cause this slow down?

Thank you,

Calvin

#254499
May 07, 2021 19:36
Vote:
 

I will look into this and get back to you. 

#254616
May 10, 2021 12:28
Vote:
 

You don't have to call foreach, just 

_associationRepository.RemoveAssociations(existing);

should be enough.

I'm not quite sure why it is much slower thought. Could you profile it using dotTrace to see where the bottlenecks are ?

#254620
May 10, 2021 13:08
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.