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

Performance: Use get_term() instead of term_exists() for get_term_tree() #2883

Merged
merged 4 commits into from
Jul 25, 2022
Merged

Performance: Use get_term() instead of term_exists() for get_term_tree() #2883

merged 4 commits into from
Jul 25, 2022

Conversation

rebeccahum
Copy link
Contributor

Description of the Change

This is a follow-up to the change in #2687. It'd be better to use get_term() to utilize the Object cache, since term_exists() does a DB call and thus, if there are several terms with the same parent, that generates a lot of queries.

Alternate Designs

N/A.

Possible Drawbacks

N/A.

Verification Process

Did the same steps described in #2687 but ensure that object caching is utilized.

Checklist:

  • I have read the CONTRIBUTING document.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests passed.

Changelog Entry

Changed: Improved performance in get_term_tree()

Credits

Props @rebeccahum

@rebeccahum rebeccahum changed the title Performance: Use get_term() instead of term_exists() Performance: Use get_term() instead of term_exists() for get_term_tree() Jul 8, 2022
@felipeelia felipeelia added this to the 4.3.0 milestone Jul 10, 2022
@felipeelia felipeelia self-assigned this Jul 10, 2022
@felipeelia felipeelia modified the milestones: 4.3.0, 4.2.2 Jul 12, 2022
@felipeelia
Copy link
Member

@rebeccahum looking at the get_term() documentation, it can also return null for some specific failures, so we'll probably have to test for that in addition to the is_wp_error() you already have there.

@felipeelia felipeelia modified the milestones: 4.2.2, 4.3.0 Jul 12, 2022
@rebeccahum
Copy link
Contributor Author

@felipeelia I've updated it to account for a null return.

@felipeelia felipeelia merged commit 1c47459 into 10up:develop Jul 25, 2022
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