Skip to content

Increase DeleteCategoryAsync perfomrance in CagegoryService.cs #8050

@ahmadkq

Description

@ahmadkq

Let us change the code from

public virtual async Task DeleteCategoryAsync(Category category)
{
    await _categoryRepository.DeleteAsync(category);

    //reset a "Parent category" property of all child subcategories
    var subcategories = await GetAllCategoriesByParentCategoryIdAsync(category.Id, true);
    foreach (var subcategory in subcategories)
    {
        subcategory.ParentCategoryId = 0;
        await UpdateCategoryAsync(subcategory);
    }
}

TO

public virtual async Task DeleteCategoryAsync(Category category)
{
    await _categoryRepository.DeleteAsync(category);

    //reset a "Parent category" property of all child subcategories
    var subcategories = await GetAllCategoriesByParentCategoryIdAsync(category.Id, true);
    foreach (var subcategory in subcategories)
    {
        subcategory.ParentCategoryId = 0;
    }
    await _categoryRepository.UpdateAsync(subcategories);
}

Metadata

Metadata

Assignees

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions