Problem/Motivation

The code to determine the list of un-aliased paths in drupal_lookup_path() is:

$cache['no_aliases'][$path_language] = array_flip(array_diff_key($cache['system_paths'], array_keys($cache['map'][$path_language])));

Given the following path arrays:

$cache[system_paths] ==>
Array
(
    [0] => node/1
    [1] => node/2
    [2] => node/3
    [3] => node/4
    [4] => node/5
    [5] => user/2/edit
    [6] => /user/logout
    [7] => taxonomy/term/1
    [8] => taxonomy/term/2
    [9] => taxonomy/term/3
    [10] => taxonomy/term/4
    [11] => taxonomy/term/5
)
$cache[map][$path_language] ==>
Array
(
    [node/1] => node-1
    [taxonomy/term/1] => taxonomy-term-1
    [taxonomy/term/2] => taxonomy-term-2
    [taxonomy/term/3] => taxonomy-term-3
)

the above code has the un-aliased list as:

$cache[no_aliases][$path_language] ==>
Array
(
    [node/5] => 4
    [user/2/edit] => 5
    [/user/logout] => 6
    [taxonomy/term/1] => 7
    [taxonomy/term/2] => 8
    [taxonomy/term/3] => 9
    [taxonomy/term/4] => 10
    [taxonomy/term/5] => 11
)

when in fact the list should be:

$cache[no_aliases][$path_language] ==>
Array
(
    [node/2] => 1
    [node/3] => 2
    [node/4] => 3
    [node/5] => 4
    [user/2/edit] => 5
    [/user/logout] => 6
    [taxonomy/term/4] => 10
    [taxonomy/term/5] => 11
)

Proposed resolution

Fix the expression by replacing array_diff_key() with array_diff().

Remaining tasks

Review and test.

User interface changes

None.

API changes

None.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

solotandem’s picture

Status: Active » Needs review
FileSize
1.07 KB

Attached patch implements proposed resolution.

dzutaro’s picture

This performance bug still exists in Drupal 7.50.

Oscaner’s picture

This performance bug still exists in Drupal 8.7.x. But not in drupal_lookup_path() function, it's in the AliasManager class.

The uploaded images are my debug informations.

Lendude’s picture

Version: 8.7.x-dev » 9.1.x-dev
Status: Needs review » Needs work
Issue tags: +Bug Smash Initiative

Moving to the right version

raman.b’s picture

Issue tags: +Needs tests
FileSize
898 bytes

Adding a patch for the current dev branch and tagging for tests

Spokje’s picture

Assigned: Unassigned » Spokje

Hmmm, the fact that path #5 passes without TestBot complaining seems to point to the fact that there was no test-coverage of getAliasByPath for this specific case.

Anyway, as @raman.b correctly pointed out, there must be tests for this issue.
Let me see if I can come up with some.

Spokje’s picture

Assigned: Spokje » Unassigned

Tried to come up with tests, but couldn't find a decent way to test this.

Version: 9.1.x-dev » 9.3.x-dev

Drupal 9.1.10 (June 4, 2021) and Drupal 9.2.10 (November 24, 2021) were the last bugfix releases of those minor version series. Drupal 9 bug reports should be targeted for the 9.3.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.