Make WordPress Core


Ignore:
Timestamp:
11/04/2016 06:03:51 AM (10 years ago)
Author:
westonruter
Message:

Customize: Combine Ajax requests for initial load of available nav menu items into a single request.

When there are many post types registered, prevent Ajax requests from piling up and slamming WordPress with concurrent requests.

Props curdin, westonruter.
Fixes #36697.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/ajax/CustomizeMenus.php

    r39038 r39137  
    175175                        array(
    176176                                array(
     177                                        'type'     => 'post_type',
     178                                        'object'   => '',
     179                                ),
     180                                array(
     181                                        'success'  => false,
     182                                        'data'     => 'nav_menus_missing_type_or_object_parameter',
     183                                ),
     184                        ),
     185                        // Testing empty type.
     186                        array(
     187                                array(
    177188                                        'type'     => '',
    178189                                        'object'   => 'post',
    … …  
    183194                                ),
    184195                        ),
    185                         // Testing empty type.
    186                         array(
    187                                 array(
    188                                         'type'     => '',
    189                                         'object'   => 'post',
     196                        // Testing empty type of a bulk request.
     197                        array(
     198                                array(
     199                                        'item_types' => array(
     200                                                array(
     201                                                        'type'     => 'post_type',
     202                                                        'object'   => 'post',
     203                                                ),
     204                                                array(
     205                                                        'type'     => 'post_type',
     206                                                        'object'   => '',
     207                                                ),
     208                                        ),
    190209                                ),
    191210                                array(
    … …  
    274293                                        'type'     => 'taxonomy',
    275294                                        'object'   => 'post_tag',
     295                                ),
     296                                true,
     297                        ),
     298                        // Testing a bulk request.
     299                        array(
     300                                array(
     301                                        'item_types' => array(
     302                                                array(
     303                                                        'type'     => 'post_type',
     304                                                        'object'   => 'post',
     305                                                ),
     306                                                array(
     307                                                        'type'     => 'post_type',
     308                                                        'object'   => 'page',
     309                                                ),
     310                                        ),
    276311                                ),
    277312                                true,
    … …  
    314349                $response = json_decode( $this->_last_response, true );
    315350
    316                 $this->assertNotEmpty( $response['data']['items'] );
     351                $this->assertNotEmpty( current( $response['data']['items'] ) );
    317352
    318353                // Get the second index to avoid the home page edge case.
    319                 $test_item = $response['data']['items'][1];
     354                $first_prop = current( $response['data']['items'] );
     355                $test_item = $first_prop[1];
    320356
    321357                foreach ( $expected_keys as $key ) {
    … …  
    326362                // Special test for the home page.
    327363                if ( 'page' === $test_item['object'] ) {
    328                         $home = $response['data']['items'][0];
     364                        $first_prop = current( $response['data']['items'] );
     365                        $home = $first_prop[0];
    329366                        foreach ( $expected_keys as $key ) {
    330367                                if ( 'object_id' !== $key ) {
Note: See TracChangeset for help on using the changeset viewer.