| 1 | Index: src/wp-includes/post.php
|
|---|
| 2 | ===================================================================
|
|---|
| 3 | --- src/wp-includes/post.php (revision 60000)
|
|---|
| 4 | +++ src/wp-includes/post.php (working copy)
|
|---|
| 5 | @@
|
|---|
| 6 | function get_post_status( $post ) {
|
|---|
| 7 | $post = get_post( $post );
|
|---|
| 8 |
|
|---|
| 9 | if ( ! $post ) {
|
|---|
| 10 | return false;
|
|---|
| 11 | }
|
|---|
| 12 |
|
|---|
| 13 | - return $post->post_status;
|
|---|
| 14 | + // Cache the post status to avoid repeated object access.
|
|---|
| 15 | + static $status_cache = array();
|
|---|
| 16 | + if ( isset( $status_cache[ $post->ID ] ) ) {
|
|---|
| 17 | + return $status_cache[ $post->ID ];
|
|---|
| 18 | + }
|
|---|
| 19 | + $status_cache[ $post->ID ] = $post->post_status;
|
|---|
| 20 | + return $status_cache[ $post->ID ];
|
|---|
| 21 | }
|
|---|
| 22 |
|
|---|
| 23 | Index: src/wp-includes/user.php
|
|---|
| 24 | ===================================================================
|
|---|
| 25 | --- src/wp-includes/user.php (revision 60000)
|
|---|
| 26 | +++ src/wp-includes/user.php (working copy)
|
|---|
| 27 | @@
|
|---|
| 28 | function get_userdata( $user_id ) {
|
|---|
| 29 | $user_id = absint( $user_id );
|
|---|
| 30 | if ( ! $user_id ) {
|
|---|
| 31 | return false;
|
|---|
| 32 | }
|
|---|
| 33 |
|
|---|
| 34 | - $user = wp_cache_get( $user_id, 'users' );
|
|---|
| 35 | - if ( $user ) {
|
|---|
| 36 | - return $user;
|
|---|
| 37 | - }
|
|---|
| 38 | -
|
|---|
| 39 | - $user = WP_User::get_data_by( 'id', $user_id );
|
|---|
| 40 | - if ( ! $user ) {
|
|---|
| 41 | - return false;
|
|---|
| 42 | - }
|
|---|
| 43 | -
|
|---|
| 44 | - wp_cache_set( $user_id, $user, 'users' );
|
|---|
| 45 | -
|
|---|
| 46 | - return $user;
|
|---|
| 47 | + // Use object cache for user data to improve performance.
|
|---|
| 48 | + $user = wp_cache_get( $user_id, 'users' );
|
|---|
| 49 | + if ( false !== $user ) {
|
|---|
| 50 | + return $user;
|
|---|
| 51 | + }
|
|---|
| 52 | +
|
|---|
| 53 | + $user = WP_User::get_data_by( 'id', $user_id );
|
|---|
| 54 | + if ( ! $user ) {
|
|---|
| 55 | + return false;
|
|---|
| 56 | + }
|
|---|
| 57 | +
|
|---|
| 58 | + wp_cache_set( $user_id, $user, 'users' );
|
|---|
| 59 | + return $user;
|
|---|
| 60 | }
|
|---|