[wp-trac] [WordPress Trac] #51796: Raw post data instead of WP_Post instances
WordPress Trac
noreply at wordpress.org
Tue Nov 17 13:00:41 UTC 2020
#51796: Raw post data instead of WP_Post instances
--------------------------+-----------------------------
Reporter: screamingdev | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version:
Severity: normal | Keywords:
Focuses: performance |
--------------------------+-----------------------------
Within WP_Query::get_posts you find:
{{{#!php
// Convert to WP_Post objects.
if ( $this->posts ) {
$this->posts = array_map( 'get_post', $this->posts
);
}
}}}
This costs a lot of time when fetching a lot of posts (e.g. products,
orders, etc).
It could be fasten up by fetching only the field "ids" but this is also
bad because when we need the post_content then a "get_post( 123 )" would
do another query.
To bypass all of this a new "fields operator" could be added:
{{{#!php
if ( $this->posts && $q['fields'] !== 'raw' ) {
$this->posts = array_map( 'get_post', $this->posts
);
}
}}}
The SQL-Query would still fetch all data but we would prevent the data
from going through the "get_post" stuff.
In times of Generator it is ridiculous to iterate over the same set of
data multiple times. By receiving the raw data the developer can decide
when to generate a WP_Post object.
Note:
filter = "raw" could imply "suppress_filters" = true because we no longer
carry WP_Post objects. But it should be allowed by the developer to switch
"suppress_filters = false" again because the stdObjects have almost the
same structure as WP_Post objects. This means (in short):
{{{#!php
if ( ! isset( $q['suppress_filters'] ) ) {
$q['suppress_filters'] = ($q['filter'] === 'raw' ?
true: false);
}
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/51796>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list