Make WordPress Core


Ignore:
Timestamp:
09/26/2015 04:01:05 PM (9 years ago)
Author:
boonebgorges
Message:

Improve post field lazyloading for comments.

[34583] modified comment queries so that all post fields are no longer loaded
by default. Instead, they are loaded only when requested on individual comment
objects. This changeset improves that flow:

  • WP_Comment magic methods __isset() and __get() should only load the post when a post field is being requested.
  • The new update_comment_post_cache argument for WP_Comment_Query allows developers to specify that, when comments are queried, all of the posts matching those comments should be loaded into cache with a single DB hit. This parameter defaults to false, since typical comment queries are linked to a single post.

Fixes #27571.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/comment.php

    r34546 r34599  
    340340        $this->assertEquals( array( $c3 ), array_values( wp_list_pluck( $children[ $c2 ]->get_children(), 'comment_ID' ) ) );
    341341    }
     342
     343    /**
     344     * @group 27571
     345     */
     346    public function test_post_properties_should_be_lazyloaded() {
     347        $p = $this->factory->post->create();
     348
     349        $c = $this->factory->comment->create( array( 'comment_post_ID' => $p ) );
     350
     351        $post = get_post( $p );
     352        $comment = get_comment( $c );
     353
     354        $post_fields = array( 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_excerpt', 'post_status', 'comment_status', 'ping_status', 'post_name', 'to_ping', 'pinged', 'post_modified', 'post_modified_gmt', 'post_content_filtered', 'post_parent', 'guid', 'menu_order', 'post_type', 'post_mime_type', 'comment_count' );
     355
     356        foreach ( $post_fields as $pf ) {
     357            $this->assertTrue( isset( $comment->$pf ), $pf );
     358            $this->assertSame( $post->$pf, $comment->$pf, $pf );
     359        }
     360    }
    342361}
Note: See TracChangeset for help on using the changeset viewer.