Make WordPress Core


Ignore:
Timestamp:
09/13/2023 02:32:33 PM (20 months ago)
Author:
spacedmonkey
Message:

REST API: Avoid unnecessarily preparing item links REST API index.

Building upon the changes introduced in [53760], this commit refines the behavior of the REST API index. Specifically, it addresses performance concerns related to the unnecessary preparation of item links, such as site icon and logo links.

Prior to this update, the index controller was invoking the prepare_links method regardless of whether the _links or _embedded fields were requested in the response. This led to unnecessary database lookups and decreased overall performance.

In this commit, we implement a more efficient approach. Now, the prepare_links method will only be called when the _links or _embedded fields are explicitly requested in the response. This optimization ensures that we prepare links only when they are intended for inclusion in the API response, reducing unnecessary overhead.

By implementing this improvement, we enhance the overall efficiency and performance of the WordPress core REST API index controller.

Props spacedmonkey, niravsherasiya7707, dlh, mukesh27, costdev, swissspidy.
Fixes #57902.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api.php

    r55562 r56566  
    25132513        $this->assertArrayHasKey( 'routes', $preload_data['/']['body'] );
    25142514
    2515         // Filtered request only has the desired fields + links
     2515        // Filtered request only has the desired fields.
    25162516        $this->assertSame(
    25172517            array_keys( $preload_data['/?_fields=description']['body'] ),
    2518             array( 'description', '_links' )
     2518            array( 'description' )
    25192519        );
    25202520    }
Note: See TracChangeset for help on using the changeset viewer.