Administration: Improve performance of List Tables.

Improve the performance of `WP_List_Table::get_column_info()` by adding the primary column to the cached header values. This reduces the number of calls to the `WP_List_Table::get_primary_column_name()` method to once per table in line with the other header getter functions.

Props bobbingwide, chaion07, costdev, mikeschroder, mukesh27, peterwilsoncc, shetheliving, spacedmonkey.
Fixes #34564.


Built from https://develop.svn.wordpress.org/trunk@53868


git-svn-id: http://core.svn.wordpress.org/trunk@53427 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Peter Wilson 2022-08-09 00:33:11 +00:00
parent 3f12697795
commit f627535216
2 changed files with 12 additions and 3 deletions

View File

@ -1108,7 +1108,10 @@ class WP_List_Table {
*/ */
protected function get_column_info() { protected function get_column_info() {
// $_column_headers is already set / cached. // $_column_headers is already set / cached.
if ( isset( $this->_column_headers ) && is_array( $this->_column_headers ) ) { if (
isset( $this->_column_headers ) &&
is_array( $this->_column_headers )
) {
/* /*
* Backward compatibility for `$_column_headers` format prior to WordPress 4.3. * Backward compatibility for `$_column_headers` format prior to WordPress 4.3.
* *
@ -1116,12 +1119,18 @@ class WP_List_Table {
* column headers property. This ensures the primary column name is included * column headers property. This ensures the primary column name is included
* in plugins setting the property directly in the three item format. * in plugins setting the property directly in the three item format.
*/ */
if ( 4 === count( $this->_column_headers ) ) {
return $this->_column_headers;
}
$column_headers = array( array(), array(), array(), $this->get_primary_column_name() ); $column_headers = array( array(), array(), array(), $this->get_primary_column_name() );
foreach ( $this->_column_headers as $key => $value ) { foreach ( $this->_column_headers as $key => $value ) {
$column_headers[ $key ] = $value; $column_headers[ $key ] = $value;
} }
return $column_headers; $this->_column_headers = $column_headers;
return $this->_column_headers;
} }
$columns = get_column_headers( $this->screen ); $columns = get_column_headers( $this->screen );

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '6.1-alpha-53867'; $wp_version = '6.1-alpha-53868';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.