Skip to content
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

[Enhancement]: reduce calls to wp_count_posts( 'product' ) from OnboardingTasks #43768

Closed
barryhughes opened this issue Jan 17, 2024 · 2 comments · Fixed by #45125
Closed

[Enhancement]: reduce calls to wp_count_posts( 'product' ) from OnboardingTasks #43768

barryhughes opened this issue Jan 17, 2024 · 2 comments · Fixed by #45125
Assignees
Labels
focus: performance The issue/PR is related to performance. focus: setup checklist Issue related to onboarding task list. team: Ghidorah type: enhancement The issue is a request for an enhancement.

Comments

@barryhughes
Copy link
Member

barryhughes commented Jan 17, 2024

Describe the solution you'd like

I was looking at #36652, which complained we are calling wp_count_posts( 'product' ) on each admin request. That particular issue was specifically interested in the call stemming from some WC_Install code, but there are other sources too, one of which is the following chain:

  • Automattic\WooCommerce\Admin\Features\OnboardingTasks\TaskLists::menu_task_count()
  • Automattic\WooCommerce\Admin\Features\OnboardingTasks\TaskLists::setup_tasks_remaining()
  • Automattic\WooCommerce\Admin\Features\OnboardingTasks\TaskList::is_complete()
  • Automattic\WooCommerce\Admin\Features\OnboardingTasks\Tasks\Products::is_complete()
  • Automattic\WooCommerce\Admin\Features\OnboardingTasks\Tasks\Products::has_products()
  • wp_count_posts()

I wonder if this (the number of requests in which we need to call wp_count_posts()) could be reduced via transient caching or similar? Post counts are already cached by WP, but only on a per-request basis (unless persistent object caching is present).

Describe alternatives you've considered

Instead of using transient based caching, perhaps other heuristics are available? Mostly wanted to flag since it's a complaint that's cropped up in other contexts, too, like #31029 (which complains about essentially the same thing, but via WC Tracker).

Additional context

I wonder if it would make sense to address in tandem with #36195?

@barryhughes barryhughes added type: enhancement The issue is a request for an enhancement. status: awaiting triage This is a newly created issue waiting for triage. focus: setup checklist Issue related to onboarding task list. team: Ghidorah labels Jan 17, 2024
@adrianduffell
Copy link
Contributor

adrianduffell commented Jan 29, 2024

I think menu_tasks_count() might be a good candidate to be cached in a transient. It seems like it would be generating multiple queries on every page load 🤔

For wp_count_posts(), I'd prefer to rely on the native persistent object caching and encourage sites to use this to solve bad performance. I understand many hosts have this enabled?

@barryhughes
Copy link
Member Author

I understand many hosts have this enabled?

Well, I don't know. It would be nice to assume so, but I also don't think we capture this via Tracker, though perhaps there are other sources we could look at. Mostly, just wanted to get this on your radar so you could make an assessment 🙌🏼

@psealock psealock removed the status: awaiting triage This is a newly created issue waiting for triage. label Jan 31, 2024
@barryhughes barryhughes added the focus: performance The issue/PR is related to performance. label Feb 14, 2024
@chihsuan chihsuan self-assigned this Feb 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
focus: performance The issue/PR is related to performance. focus: setup checklist Issue related to onboarding task list. team: Ghidorah type: enhancement The issue is a request for an enhancement.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants