Skip to content

Suppress content filters on internal asset bookkeeping queries#1199

Draft
utkarshcloudinary wants to merge 1 commit into
developfrom
fix/suppress-filters-internal-queries
Draft

Suppress content filters on internal asset bookkeeping queries#1199
utkarshcloudinary wants to merge 1 commit into
developfrom
fix/suppress-filters-internal-queries

Conversation

@utkarshcloudinary

Copy link
Copy Markdown
Collaborator

Summary

Assets::init_asset_parents() and Assets::process_parent_assets() run internal WP_Query lookups over Cloudinary's own asset post type. They are pure plugin bookkeeping, but because they are normal WP_Query instantiations they still fire third-party the_posts / posts_results content filters.

If an active theme or plugin hooks the_posts with expensive work, that work runs on every Cloudinary internal query. This was reported on an enterprise site whose theme injects author-archive results on the_posts (running get_users() + count_user_posts() per query); with Cloudinary's paginated internal queries this repeated until PHP's memory limit was exhausted and pages 500'd.

Change

Add 'suppress_filters' => true to the two fully-specified internal queries so they skip content filters entirely — correct behaviour for internal bookkeeping that has nothing to do with public-facing content.

Note on WordPressVIPMinimum.SuppressFilters

The VIP standard prohibits suppress_filters => true because it also disables posts_where/posts_join/posts_orderby (used by VIP infra and multilingual plugins). These two queries are fully specified by post type / parent / status and do not rely on those filters, so the rule is suppressed inline with an explanatory comment. Existing precedent for VIP-restricted query usage in this codebase: php/cache/class-cache-point.php:439.

Status / caveats

  • Draft. The customer crash in our logs is a different fatal (undefined have_rows() from their theme during Cloudinary activation — see separate work). This PR addresses the memory-exhaustion interaction reproduced locally against the customer theme, which is not yet confirmed to be the issue the customer currently faces.
  • Recommend holding merge until the customer confirms the temporary mu-plugin mitigation resolves their crash.

Testing

  • init_asset_parents() still populates asset parents correctly
  • process_parent_assets() still iterates child assets correctly
  • With a theme filtering the_posts, that filter no longer runs on Cloudinary internal queries
  • No regression for WPML / multilingual asset 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants