[wp-trac] [WordPress Trac] #35816: Add "after_get_posts" action to `WP_Query::get_posts()`

WordPress Trac noreply at wordpress.org
Wed Feb 17 03:26:38 UTC 2016


#35816: Add "after_get_posts" action to `WP_Query::get_posts()`
-------------------------------------+--------------------------
 Reporter:  stevegrunwell            |       Owner:
     Type:  defect (bug)             |      Status:  new
 Priority:  normal                   |   Milestone:  4.5
Component:  Query                    |     Version:  trunk
 Severity:  normal                   |  Resolution:
 Keywords:  has-patch needs-testing  |     Focuses:  performance
-------------------------------------+--------------------------
Changes (by boonebgorges):

 * keywords:   => has-patch needs-testing


Comment:

 [attachment:35816.3.diff] is a full patch ready for review and feedback.

 It looks a little bit bonkers, but I think it's a good long-term solution.
 Let me summarize what's going on for people who are just joining us :)

 - In 4.4, we introduced the concept of "lazyloading" commentmeta and
 termmeta. This means that, in loops where we have a full set of object IDs
 (post IDs, comment IDs), we don't query the database for any term meta or
 comment meta until the first time `get_term_meta()` or
 `get_comment_meta()` is called in the loop. When that happens, metadata
 for all relevant objects is loaded, with a single query, into the cache.
 - The idea behind this technique is good, but the 4.4 implementation
 involved a callback method on `WP_Query`. This means that `WP_Query`
 objects were getting stored in the `$wp_filter` global. And `WP_Query`
 objects can get very, very large, as when you have a huge number of posts
 or the `post_content` is very big.
 - [attachment:35816.3.diff] refines the concept by introducing a central
 queue for objects waiting to have their metadata lazyloaded. So, for
 example, during a comments loop like `wp_list_comments()`, comment IDs are
 queued into the `WP_Metadata_Lazyloader` singleton. It's this (much
 smaller) singleton that contains the callback that gets hooked to
 `'get_comment_metadata'`. Likewise for termmeta for terms belonging to
 posts in a `WP_Query` loop.

 The metadata loader is meant to be fairly abstract, so that we can easily
 implement the same technique for other kinds of metadata and loops - like
 users, or even postmeta - at some point in the future.

 (@lpawlik it also contains your `reset()` idea. I accidentally deleted
 your most recent patch, though - sorry!)

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


More information about the wp-trac mailing list