ACSD-47027: slow query B2B CompanyRole GraphQL update

The ACSD-47027 patch solves the issue where the slow query B2B CompanyRole GraphQL update does not work as expected. This patch is available when the Quality Patches Tool (QPT) 1.1.23 is installed. The patch ID is ACSD-47027. Please note that the issue is scheduled to be fixed in Adobe Commerce 2.4.6.

Affected products and versions

The patch is created for Adobe Commerce version:

  • Adobe Commerce (all deployment methods) 2.4.2-p1

Compatible with Adobe Commerce versions:

  • Adobe Commerce (all deployment methods) 2.4.2 - 2.4.5-p1
NOTE
The patch might become applicable to other versions with new Quality Patches Tool releases. To check if the patch is compatible with your Adobe Commerce version, update the magento/quality-patches package to the latest version and check the compatibility on the Quality Patches Tool: Search for patches page. Use the patch ID as a search keyword to locate the patch.

Issue

The slow query B2B CompanyRole GraphQL update does not work as expected.

Prerequisites:

Install the B2B module.

Steps to reproduce:

  1. In the Adobe Commerce Admin, go to Stores > Settings > Configurations > B2B Features and set Enable Company to Yes.

  2. Go to the frontend and create a company.

  3. After you log in as a company user, go to My Account > Roles and Permissions and add a new role.

  4. Enable dev query log using bin/magento dev:que:enab.

  5. Now send the below GraphQL request (id is the base64 encoded role id):

    code language-none
    
    mutation {
    updateCompanyRole(
       input: {
          id: "Mg=="
          permissions: [
          "Magento_Company::view"
          "Magento_Company::view_account"
          "Magento_Company::user_management"
          "Magento_Company::roles_view"
         ]
       }
     ) {
       role {
          id
    
      name
    
      permissions {
      id
    
      text
    
      children {
         id
    
         text
    
         children {
            id
    
            text
          }
        }
      }
    }
    
  6. Check the query log.

  7. You can see that the above query is executed. This query is executed in app/code/Magento/CompanyGraphQl/Model/Company/Role/ValidateRole.php::validateResources.

Expected results:

The app/code/Magento/CompanyGraphQl/Model/Company/Role/ValidateRole.php::validateResources needs to be optimized to avoid loading all the data available in the company_permissions DB table.

Actual results:

Adobe Commerce executes a query without any filter. When there are a large number of records, it takes a lot of time for Adobe Commerce to prepare the data collection.

Apply the patch

To apply individual patches, use the following links depending on your deployment method:

To learn more about Quality Patches Tool, refer to:

For info about other patches available in QPT, refer to Quality Patches Tool: Search for patches in the Quality Patches Tool guide.

recommendation-more-help
8bd06ef0-b3d5-4137-b74e-d7b00485808a