Skip to content

Fix performance issues with structured data and products with lots of variations #59431

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 17, 2025

Conversation

MajorChump
Copy link
Contributor

@MajorChump MajorChump commented Jul 4, 2025

Submission Review Guidelines:

Changes proposed in this Pull Request:

Closes #55799 .

(For Bug Fixes) Bug introduced in PR #52105 .

Screenshots or screen recordings:

Before After

How to test the changes in this Pull Request:

Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:

  1. Create a product with thousands to tens of thousands of variations with a sale price
  2. Navigate to the product page, the loading time should take a long time
  3. Apply the changes navigate to the same page and the loading time will be near instant
  4. Compare ld+json in HTML no differences should be visible

Testing that has already taken place:Tested on our live site which has products with 10k+ variations. Load times reduced from 20-30 seconds to under a second.

Changelog entry

  • Automatically create a changelog entry from the details below.
  • This Pull Request does not require a changelog entry. (Comment required below)
Changelog Entry Details

Significance

  • Patch
  • Minor
  • Major

Type

  • Fix - Fixes an existing bug
  • Add - Adds functionality
  • Update - Update existing functionality
  • Dev - Development related task
  • Tweak - A minor adjustment to the codebase
  • Performance - Address performance issues
  • Enhancement - Improvement to existing functionality

Message

Changelog Entry Comment

Comment

Summary by CodeRabbit

  • Performance Improvements
    • Enhanced handling of structured data for products with many variations, resulting in faster performance.
  • Changelog
    • Added a new entry documenting the performance improvements for the WooCommerce plugin.

@github-actions github-actions bot added type: community contribution plugin: woocommerce Issues related to the WooCommerce Core plugin. labels Jul 4, 2025
Copy link
Contributor

coderabbitai bot commented Jul 4, 2025

"""

Walkthrough

A changelog entry was added documenting a patch release for the WooCommerce plugin, highlighting performance improvements related to structured data and variable products with many variations. The core code change refactors the logic for determining the lowest sale price among product variations, replacing a manual iteration with a more efficient built-in method.

Changes

Files / Grouped Files Change Summary
plugins/woocommerce/changelog/2025-07-04-10-33-20-580699 Added changelog entry for a patch release focusing on structured data performance improvements.
plugins/woocommerce/includes/class-wc-structured-data.php Refactored logic to use get_variation_sale_price for finding the lowest sale price among variations, improving performance.

Assessment against linked issues

Objective Addressed Explanation
Refactor structured data logic to use get_variation_sale_price for variable products, improving performance (#55799)
Remove inefficient use of array_map and wc_get_product for finding variation sale prices (#55799)
Ensure no changes to public APIs or exported entities as part of the performance fix (#55799)

Suggested reviewers

  • jimjasson
    """

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1154e33 and 7beb696.

📒 Files selected for processing (1)
  • plugins/woocommerce/includes/class-wc-structured-data.php (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • plugins/woocommerce/includes/class-wc-structured-data.php
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@MajorChump
Copy link
Contributor Author

@jorgeatorres this is same the as #56855 but with the corrections you requested.

Could you review please?

@jorgeatorres jorgeatorres requested review from a team and albarin and removed request for a team July 9, 2025 08:12
Copy link
Contributor

github-actions bot commented Jul 9, 2025

Testing Guidelines

Hi ,

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.

@albarin
Copy link
Contributor

albarin commented Jul 15, 2025

Hi @MajorChump, thanks a lot for your contribution!
It tests well regarding performance 👌

I think there's a case where though in which the result could be slightly different than before, if there's a product with the following 3 variations 👇 the validThrough field with the current code will return 2025-10-30 but after this PR change it will return 2025-10-31:

Variation Price Sale price Sale end date
A 10 - -
B 12 5 2025-10-31
C 10 5 2025-10-30

Would be great if you could add some tests to it.

Thanks a lot again!

@MajorChump
Copy link
Contributor Author

Hi @albarin I believe you're correct, both the existing code and my changes seem to be arbitrary in terms of the date selected for on sale to date - I think the regression here makes no difference as it was random to begin with.

In a real world scenario, variations of the same product discounted to the same price most likely will come out of sale at the same time so may be a none issue.

How do you want to proceed?

@albarin
Copy link
Contributor

albarin commented Jul 17, 2025

Hey @MajorChump, thanks for your reply!

Hi @albarin I believe you're correct, both the existing code and my changes seem to be arbitrary in terms of the date selected for on sale to date - I think the regression here makes no difference as it was random to begin with.

After some discussion, we think this is ok, as it seems the date was also arbitrarily selected before.

There's a small detail that would be good to correct: the code is using the variable $variation_id outside the foreach loop where it is defined. I know PHP allows for this, but it could lead to other issues when calling wc_get_product if it's not set.

Thanks a lot!

@MajorChump
Copy link
Contributor Author

@albarin Thank you, changes made as requested.

Thanks,

Copy link
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.

Tested on a product with thousands of variations and confirmed that the loading time is significantly improved and the LD-JSON is equivalent.

@albarin albarin merged commit bf1915f into woocommerce:trunk Jul 17, 2025
36 checks passed
@github-actions github-actions bot added this to the 10.1.0 milestone Jul 17, 2025
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. type: community contribution
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Performance]: Structured Data is extremely slow for sites with lots of variations which have variations on sale due to PR (#52105)
2 participants