Skip to content

Commit 7f7cf79

Browse files
committed
Suppress content filters on internal asset bookkeeping queries
init_asset_parents() and process_parent_assets() run internal WP_Query lookups over Cloudinary's own asset post type. These are not public-facing content queries, but they still fire third-party the_posts/posts_results filters, which can cause a theme/plugin to run expensive per-query work (e.g. author-archive injection) on every one of Cloudinary's internal queries until the request exhausts memory. Set suppress_filters => true on these fully-specified internal queries so they skip content filters. The WordPressVIPMinimum SuppressFilters rule is suppressed with an explanation: these queries do not rely on the posts_where/join/orderby filters the rule protects.
1 parent 687f24a commit 7f7cf79

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

php/class-assets.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,14 +601,19 @@ private function process_parent_assets( $parent_id, $callback ) {
601601
return;
602602
}
603603

604-
$query_args = array(
604+
$query_args = array(
605605
'post_type' => self::POST_TYPE_SLUG,
606606
'posts_per_page' => 100,
607607
'post_parent' => $parent_id,
608608
'post_status' => array( 'inherit', 'draft' ),
609609
'fields' => 'ids',
610610
'update_post_meta_cache' => false,
611611
'update_post_term_cache' => false,
612+
// Internal bookkeeping query over our own post type: do not run
613+
// third-party content filters (e.g. `the_posts`) meant for
614+
// public-facing queries. The query is fully specified, so the
615+
// filters VIP protects (posts_where/join/orderby) are not relied on.
616+
'suppress_filters' => true, // phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.SuppressFilters_suppress_filters
612617
);
613618
$query = new \WP_Query( $query_args );
614619
$previous_total = $query->found_posts;
@@ -987,6 +992,11 @@ protected function init_asset_parents() {
987992
'no_found_rows' => true,
988993
'update_post_meta_cache' => false,
989994
'update_post_term_cache' => false,
995+
// Internal bookkeeping query over our own post type: do not run
996+
// third-party content filters (e.g. `the_posts`) meant for
997+
// public-facing queries. The query is fully specified, so the
998+
// filters VIP protects (posts_where/join/orderby) are not relied on.
999+
'suppress_filters' => true, // phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.SuppressFilters_suppress_filters
9901000
);
9911001
$query = new \WP_Query( $args );
9921002
$this->asset_parents = array();

0 commit comments

Comments
 (0)