[wp-trac] [WordPress Trac] #50567: Set $post filter in update_post_cache()

WordPress Trac noreply at wordpress.org
Fri Jul 31 04:45:28 UTC 2020


#50567: Set $post filter in update_post_cache()
----------------------------------------+--------------------------
 Reporter:  Cybr                        |       Owner:  (none)
     Type:  defect (bug)                |      Status:  new
 Priority:  normal                      |   Milestone:  5.6
Component:  Posts, Post Types           |     Version:  trunk
 Severity:  normal                      |  Resolution:
 Keywords:  has-patch needs-unit-tests  |     Focuses:  performance
----------------------------------------+--------------------------
Changes (by peterwilsoncc):

 * keywords:   => has-patch needs-unit-tests


Comment:

 Replying to [comment:3 Cybr]:
 > Attached (`cg.zip`) are before and after CacheGrind outputs generated by
 xDebug on PHP 7.4.7 via XAMPP on a VM with generous headroom
 (16GB/4x3.8GHz).
 >
 > I've used Twenty Twenty with no plugins active on WP 5.4.2 en_US,
 displaying 20 posts (duplicated default post "Hello World!") at `/wp-
 admin/edit.php`, and 10 posts at `/` (homepage).

 Thanks for attaching the screen shots and additional summary, it's very
 much appreciated.

 I can see this happening with a very simple test plugin running on the
 `/wp-admin/edit.php` screen:

 {{{#!php
 <?php
 add_action( 'admin_enqueue_scripts', function() {
         /*
          * Post 72 is off the page (ie, this is a new query).
          *
          * The wp_cache_get dump includes `filter: raw`
          */
         var_dump( get_post( 72, OBJECT, 'display' ) );
         var_dump( wp_cache_get( 72, 'posts' ) );

         /*
          * Post 38 is on the page and has been returned by WP_Query.
          *
          * The wp_cache_get dump does not include `filter: raw`
          */
         var_dump( wp_cache_get( 38, 'posts' ) );
         var_dump( get_post( 38 ) );
         exit;
 } );
 }}}

 The one question I have about the patch is is there a situation in which
 `$post->filter` can be a value other than `raw`?

 If the cache is expected to have raw data, then it would be dandy to be
 certain that the data is indeed stored that way. Maybe it would be better
 to call `empty( $post->filter ) || $post->filter !== raw`.

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


More information about the wp-trac mailing list