[wp-trac] [WordPress Trac] #44321: REST API: Expose revision count and last revision ID on Post response

WordPress Trac noreply at wordpress.org
Fri Jun 8 21:22:18 UTC 2018


#44321: REST API: Expose revision count and last revision ID on Post response
-----------------------------------------------------+---------------------
 Reporter:  danielbachhuber                          |       Owner:  (none)
     Type:  enhancement                              |      Status:  new
 Priority:  normal                                   |   Milestone:  4.9.8
Component:  REST API                                 |     Version:
 Severity:  normal                                   |  Resolution:
 Keywords:  dev-feedback needs-unit-tests has-patch  |     Focuses:
-----------------------------------------------------+---------------------

Comment (by birgire):

 One possible improvement that comes to mind is:

 {{{
 $revisions = wp_get_post_revisions( $post->ID, array(
         'fields' => 'ids',
 ) );

 }}}

 instead of:

 {{{
 $revisions = wp_get_post_revisions( $post->ID );

 }}}

 since the patch in [attachment:44321.1.diff] only needs the ''count'' and
 the ''ID''.

 Here's the result of few test runs:

 {{{
 100 revisions:
 --------------
 time: 0.011561
 #qs: 2

 time: 0.011199
 #qs: 2

 time: 0.011316
 #qs: 2

 200 revisions:
 --------------
 time: 0.020648
 #qs: 2

 time: 0.021641
 #qs: 2

 time: 0.021116
 #qs: 2

 100 revisions (fields=ids):
 --------------
 time: 0.001606
 #qs: 1

 time: 0.001734
 #qs: 1

 time: 0.001875
 #qs: 1

 200 revisions (fields=ids):
 --------------
 time: 0.002118
 #qs: 1

 time: 0.002110
 #qs: 1

 time: 0.002875
 #qs: 1

 }}}

 where we test it with variations of:

 {{{
 global $wpdb;

 $post_id           = self::factory()->post->create();
 $revisions_count   = 100;

 foreach( range( 1, $revisions_count ) as $rng ) {
         wp_update_post( array(
                 'post_content' => $rng,
                 'ID'           => $post_id,
         ) );
 }

 $wpdb->timer_start();
 $query_count = $wpdb->num_queries;

 $revisions = wp_get_post_revisions( $post_id, array(
         'fields'         => 'ids',
 ) );

 printf( 'time: %f' . PHP_EOL, $wpdb->timer_stop() );
 printf( '#qs: %d' . PHP_EOL, $wpdb->num_queries - $query_count );

 }}}

 So from this quick testing, for 100-200 revisions, it seems to reduce the
 number of queries from 2 to 1 and runs order of magnitude times faster.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/44321#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list