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

Widget get_terms() optimization #3046

Closed
mae829 opened this issue Oct 5, 2022 · 2 comments · Fixed by #3060
Closed

Widget get_terms() optimization #3046

mae829 opened this issue Oct 5, 2022 · 2 comments · Fixed by #3060
Assignees
Milestone

Comments

@mae829
Copy link
Contributor

mae829 commented Oct 5, 2022

Is your enhancement related to a problem? Please describe.
On enterprise level websites, some taxonomies can reach large number count (10k+). I know it can be up to the client to clean that up but sometimes that will just not happen.
The large number of terms results in the call to get_terms() in the facets widget to be a large SQL query and updating the cache (when available) due to get_terms() functionality itself.

Describe the solution you'd like

  • Passing the update_term_meta_cache argument as true in the default arguments for get_terms().

Describe alternatives you've considered

  • Using global $ep_facet_aggs to limit the requested terms to the ones that actually have results.

Additional context
The ep_facet_search_get_terms_args filter definitely allows for optimization so possibly just passing the update_term_meta_cache as true argument in the defaults might suffice.

Implementation from above:

<?php
add_filter( 'ep_facet_search_get_terms_args', function( $query_args, $args, $instance ) {
	global $ep_facet_aggs;

	$query_args['update_term_meta_cache'] = false;

	if ( ! empty( $instance['facet'] ) && ! empty( $ep_facet_aggs[ $instance['facet'] ] ) ) {
		$query_args['slug'] = array_keys( $ep_facet_aggs[ $instance['facet'] ] );
	}

	return $query_args;
}, 10, 3 );
@felipeelia
Copy link
Member

Hey @mae829, thanks for the suggestion. Do you mind sending us a PR changing the get_terms call to pass update_term_meta_cache false? Thanks!

@mae829
Copy link
Contributor Author

mae829 commented Oct 14, 2022

@felipeelia sure thing.

PR created over at #3060

@felipeelia felipeelia self-assigned this Oct 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants