Skip to content

[dev] Performance: introduce new skill for using cache priming (reviews and code generation)#63706

Merged
kalessil merged 2 commits intotrunkfrom
performance/extract-cache-priming-prs-into-skill
Mar 17, 2026
Merged

[dev] Performance: introduce new skill for using cache priming (reviews and code generation)#63706
kalessil merged 2 commits intotrunkfrom
performance/extract-cache-priming-prs-into-skill

Conversation

@kalessil
Copy link
Copy Markdown
Contributor

@kalessil kalessil commented Mar 16, 2026

Submission Review Guidelines:

Changes proposed in this Pull Request:

Building on my work from Q1 2026, I created a new skill for using cache priming in our codebase through my recent PRs. In this PR, I am adding the skill to the repository and using AI-assisted cleanup to standardize existing cache priming usages.

On the PHP side, this removes stale is_callable guards, adds missing ! empty() guards, and normalises comment text to // Prime caches to reduce future queries.

How to test the changes in this Pull Request:

  • Code review only.

Please note that .ai/skills/woocommerce-performance/cache-priming.md is intended for AIs, and verified in #63713 where Claude uses it for identifying and covering gaps.

@kalessil kalessil self-assigned this Mar 16, 2026
@github-actions github-actions bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label Mar 16, 2026
@kalessil kalessil changed the title [WIP] Performance: extract cache priming PRs into a skill [WIP] Performance: extract new skill from cache priming PRs Mar 16, 2026
@kalessil kalessil force-pushed the performance/extract-cache-priming-prs-into-skill branch from 1cf36da to 5ca4e6c Compare March 17, 2026 07:05
@kalessil kalessil changed the title [WIP] Performance: extract new skill from cache priming PRs [dev] Performance: introduce new skill for using cache priming (reviews and code generation) Mar 17, 2026
@kalessil kalessil added this to the 10.7.0 milestone Mar 17, 2026
@kalessil kalessil requested a review from albarin March 17, 2026 07:23
@kalessil kalessil marked this pull request as ready for review March 17, 2026 07:23
@kalessil kalessil requested review from a team as code owners March 17, 2026 07:23
@kalessil kalessil requested review from senadir and removed request for a team March 17, 2026 07:23
@github-actions
Copy link
Copy Markdown
Contributor

Testing Guidelines

Hi @albarin @senadir @woocommerce/flux,

Apart from reviewing the code changes, please make sure to review the testing instructions (Guide) and verify that relevant tests (E2E, Unit, Integration, etc.) have been added or updated as needed.

Reminder: PR reviewers are required to document testing performed. This includes:

  • 🖼️ Screenshots or screen recordings.
  • 📝 List of functionality tested / steps followed.
  • 🌐 Site details (environment attributes such as hosting type, plugins, theme, store size, store age, and relevant settings).
  • 🔍 Any analysis performed, such as assessing potential impacts on environment attributes and other plugins, conducting performance profiling, or using LLM/AI-based analysis.

⚠️ Within the testing details you provide, please ensure that no sensitive information (such as API keys, passwords, user data, etc.) is included in this public issue.

@kalessil kalessil removed request for a team and senadir March 17, 2026 07:27
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 17, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 65391fcb-f3cf-4ab0-89b8-ec16b8cd73ff

📥 Commits

Reviewing files that changed from the base of the PR and between 5ca4e6c and 76980b4.

📒 Files selected for processing (1)
  • .ai/skills/woocommerce-performance/cache-priming.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • .ai/skills/woocommerce-performance/cache-priming.md

📝 Walkthrough

Walkthrough

Adds WooCommerce cache-priming documentation and changelog entry; replaces runtime is_callable('_prime_post_caches') guards with data presence checks or unconditional priming in multiple files; updates related comments and removes PHPStan baseline suppressions referencing the prior guards.

Changes

Cohort / File(s) Summary
Documentation & Skill
.ai/skills/woocommerce-performance/SKILL.md, .ai/skills/woocommerce-performance/cache-priming.md, plugins/woocommerce/changelog/performance-extract-cache-priming-prs-into-skill
Adds a new "WooCommerce Performance" skill and detailed cache-priming guidance (six patterns, backward-compat notes) plus a changelog entry (dev/patch).
Cart / Order / Product Factories
plugins/woocommerce/includes/class-wc-cart-session.php, plugins/woocommerce/includes/class-wc-order-factory.php, plugins/woocommerce/includes/class-wc-product-factory.php
Replaces is_callable guards with !empty() checks for priming or adds unconditional priming in product factory to pre-warm post caches for requested IDs.
Product Types & Grouping
plugins/woocommerce/includes/class-wc-product-grouped.php, plugins/woocommerce/includes/class-wc-product-variable.php
Adds non-empty ID guards around _prime_post_caches() calls (grouped) and replaces is_callable checks with !empty() checks for variation priming in variable product methods.
Data Stores
plugins/woocommerce/includes/data-stores/class-wc-product-data-store-cpt.php, plugins/woocommerce/includes/data-stores/class-wc-product-grouped-data-store-cpt.php, plugins/woocommerce/includes/data-stores/class-wc-product-variable-data-store-cpt.php
Introduces or documents cache priming for child/variation IDs before attribute/price collection to avoid extra queries; adds explanatory comments.
Templates & Shortcodes
plugins/woocommerce/includes/wc-template-functions.php, plugins/woocommerce/includes/shortcodes/class-wc-shortcode-products.php
Updates comments to state "Prime caches to reduce future queries." and removes is_callable guard in shortcode, calling _prime_post_caches() unconditionally when IDs exist.
Blocks & Store API Utilities
plugins/woocommerce/src/Blocks/Assets/AssetDataRegistry.php, plugins/woocommerce/src/Blocks/BlockTypes/AbstractProductGrid.php, plugins/woocommerce/src/Blocks/BlockTypes/RelatedProducts.php, plugins/woocommerce/src/Blocks/Utils/BlockTemplateUtils.php, plugins/woocommerce/src/StoreApi/Utilities/ProductQuery.php, plugins/woocommerce/src/StoreApi/Schemas/V1/CartSchema.php
Removes runtime is_callable guards and/or adds !empty() checks before priming; inserts cache-priming calls or clarifying comments in block registry, product grid, block templates, product query, and cart schema.
Admin & REST
plugins/woocommerce/src/Internal/Admin/ProductReviews/ReviewsUtil.php, plugins/woocommerce/src/Internal/RestApi/Routes/V4/Orders/Controller.php
Adds short clarifying comments indicating cache priming intent; no behavior changes.
Static Analysis Baseline
plugins/woocommerce/phpstan-baseline.neon
Removes baseline suppression lines related to is_callable('_prime_post_caches') narrow-type warnings across multiple files (deleted suppression entries).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: introducing a new AI skill for cache priming usage with applications to code reviews and generation.
Description check ✅ Passed The description is directly related to the changeset, explaining the purpose of the skill files, the PHP standardizations applied, and the testing approach.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch performance/extract-cache-priming-prs-into-skill
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

CodeRabbit can use your project's `phpmd` ruleset to improve the quality of PHP code reviews.

You can customize the ruleset in your CodeRabbit configuration, or provide a path to a custom ruleset file.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
plugins/woocommerce/src/Blocks/Assets/AssetDataRegistry.php (1)

157-157: Filter invalid page IDs before priming post caches.

Line 157 primes every value from $store_pages, including sentinel values (0/-1) when a store page is unset. Filtering to positive IDs avoids unnecessary cache-priming queries.

💡 Suggested change
-		_prime_post_caches( array_values( $store_pages ), false, false );
+		$page_ids_to_prime = array_filter( array_map( 'absint', array_values( $store_pages ) ) );
+		if ( ! empty( $page_ids_to_prime ) ) {
+			_prime_post_caches( $page_ids_to_prime, false, false );
+		}

As per coding guidelines **/*.{php,js,jsx,tsx,ts}: Guard all code against unexpected inputs.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@plugins/woocommerce/src/Blocks/Assets/AssetDataRegistry.php` at line 157, The
code calls _prime_post_caches( array_values( $store_pages ), false, false ) in
AssetDataRegistry but does not filter out sentinel/invalid IDs (0, -1), causing
unnecessary cache queries; before calling _prime_post_caches, filter
$store_pages to only include positive integers (e.g., array_filter with
is_int/is_numeric and > 0 or casting to int) so only valid post IDs are passed
to _prime_post_caches, leaving other logic and variable names ($store_pages,
_prime_post_caches) unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.ai/skills/woocommerce-performance/cache-priming.md:
- Around line 126-132: The example call to _prime_post_caches uses the wrong
boolean order relative to the comment: _prime_post_caches( $ids,
$update_term_cache = true, $update_meta_cache = true ). Update the example so it
actually skips meta priming and includes terms by swapping the booleans to
_prime_post_caches( $order_ids, true, false ), or alternatively, if you intended
to skip terms, adjust the comment to state that the call skips term priming;
reference the _prime_post_caches function and the $order_ids example when making
the change.

---

Nitpick comments:
In `@plugins/woocommerce/src/Blocks/Assets/AssetDataRegistry.php`:
- Line 157: The code calls _prime_post_caches( array_values( $store_pages ),
false, false ) in AssetDataRegistry but does not filter out sentinel/invalid IDs
(0, -1), causing unnecessary cache queries; before calling _prime_post_caches,
filter $store_pages to only include positive integers (e.g., array_filter with
is_int/is_numeric and > 0 or casting to int) so only valid post IDs are passed
to _prime_post_caches, leaving other logic and variable names ($store_pages,
_prime_post_caches) unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 918ce955-0703-49a6-b2ad-8b855b0611da

📥 Commits

Reviewing files that changed from the base of the PR and between bf365c7 and 5ca4e6c.

📒 Files selected for processing (22)
  • .ai/skills/woocommerce-performance/SKILL.md
  • .ai/skills/woocommerce-performance/cache-priming.md
  • plugins/woocommerce/changelog/performance-extract-cache-priming-prs-into-skill
  • plugins/woocommerce/includes/class-wc-cart-session.php
  • plugins/woocommerce/includes/class-wc-order-factory.php
  • plugins/woocommerce/includes/class-wc-product-factory.php
  • plugins/woocommerce/includes/class-wc-product-grouped.php
  • plugins/woocommerce/includes/class-wc-product-variable.php
  • plugins/woocommerce/includes/data-stores/class-wc-product-data-store-cpt.php
  • plugins/woocommerce/includes/data-stores/class-wc-product-grouped-data-store-cpt.php
  • plugins/woocommerce/includes/data-stores/class-wc-product-variable-data-store-cpt.php
  • plugins/woocommerce/includes/shortcodes/class-wc-shortcode-products.php
  • plugins/woocommerce/includes/wc-template-functions.php
  • plugins/woocommerce/phpstan-baseline.neon
  • plugins/woocommerce/src/Blocks/Assets/AssetDataRegistry.php
  • plugins/woocommerce/src/Blocks/BlockTypes/AbstractProductGrid.php
  • plugins/woocommerce/src/Blocks/BlockTypes/RelatedProducts.php
  • plugins/woocommerce/src/Blocks/Utils/BlockTemplateUtils.php
  • plugins/woocommerce/src/Internal/Admin/ProductReviews/ReviewsUtil.php
  • plugins/woocommerce/src/Internal/RestApi/Routes/V4/Orders/Controller.php
  • plugins/woocommerce/src/StoreApi/Schemas/V1/CartSchema.php
  • plugins/woocommerce/src/StoreApi/Utilities/ProductQuery.php
💤 Files with no reviewable changes (1)
  • plugins/woocommerce/phpstan-baseline.neon

Comment thread .ai/skills/woocommerce-performance/cache-priming.md
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 17, 2026

Test using WordPress Playground

The changes in this pull request can be previewed and tested using a WordPress Playground instance.
WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Test this pull request with WordPress Playground.

Note that this URL is valid for 30 days from when this comment was last updated. You can update it by closing/reopening the PR or pushing a new commit.

Copy link
Copy Markdown
Contributor

@albarin albarin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Confirmed the skill and code changes both look good

@kalessil kalessil merged commit c37c645 into trunk Mar 17, 2026
50 checks passed
@kalessil kalessil deleted the performance/extract-cache-priming-prs-into-skill branch March 17, 2026 10:03
@github-actions
Copy link
Copy Markdown
Contributor

⚠️ API Documentation Reminder

Hi @kalessil! Your PR contains REST API changes. Please consider updating the REST API documentation if your changes affect the public API.

Changed API files:

plugins/woocommerce/src/StoreApi/Schemas/V1/CartSchema.php
plugins/woocommerce/src/StoreApi/Utilities/ProductQuery.php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

plugin: woocommerce Issues related to the WooCommerce Core plugin.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants