Skip to content

Commit d5ca1d1

Browse files
committed
Better solution for issue 64194
1 parent f1cf211 commit d5ca1d1

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/wp-includes/class-wp-scripts.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,9 +1068,16 @@ private function filter_eligible_strategies( $handle, $eligible_strategies = nul
10681068
*
10691069
* @param string $handle Script module ID.
10701070
* @param array<string, true> $checked Optional. An array of already checked script handles, used to avoid recursive loops.
1071+
* @param array<string, string> $stored_results Optional. An array of already computed max priority by handle, used to increase performance in large dependency lists.
1072+
*
10711073
* @return string|null Highest fetch priority for the script and its dependents.
10721074
*/
1073-
private function get_highest_fetchpriority_with_dependents( string $handle, array &$checked = array() ): ?string {
1075+
private function get_highest_fetchpriority_with_dependents( string $handle, array $checked = array(), array &$stored_results = array() ): ?string {
1076+
if(isset($stored_results[$handle]) && !empty($stored_results[$handle])) {
1077+
return $stored_results[$handle];
1078+
}
1079+
1080+
10741081
// If there is a recursive dependency, return early.
10751082
if ( isset( $checked[ $handle ] ) ) {
10761083
return null;
@@ -1099,7 +1106,7 @@ private function get_highest_fetchpriority_with_dependents( string $handle, arra
10991106
$highest_priority_index = (int) array_search( $fetchpriority, $priorities, true );
11001107
if ( $highest_priority_index !== $high_priority_index ) {
11011108
foreach ( $this->get_dependents( $handle ) as $dependent_handle ) {
1102-
$dependent_priority = $this->get_highest_fetchpriority_with_dependents( $dependent_handle, $checked );
1109+
$dependent_priority = $this->get_highest_fetchpriority_with_dependents( $dependent_handle, $checked, $stored_results );
11031110
if ( is_string( $dependent_priority ) ) {
11041111
$highest_priority_index = max(
11051112
$highest_priority_index,
@@ -1111,7 +1118,7 @@ private function get_highest_fetchpriority_with_dependents( string $handle, arra
11111118
}
11121119
}
11131120
}
1114-
1121+
$stored_results[$handle] = $priorities[ $highest_priority_index ];
11151122
return $priorities[ $highest_priority_index ];
11161123
}
11171124

0 commit comments

Comments
 (0)