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

Add helper get_total_objects_for_query_from_db() which counts directly from the DB #2571

Merged
merged 3 commits into from
Jan 28, 2022
Merged

Add helper get_total_objects_for_query_from_db() which counts directly from the DB #2571

merged 3 commits into from
Jan 28, 2022

Conversation

rebeccahum
Copy link
Contributor

@rebeccahum rebeccahum commented Jan 26, 2022

Description of the Change

We're noticing that on very large sites, the query to count the total objects in get_total_objects_for_query() dies. This PR adds an abstracted helper method get_total_objects_for_query_from_db() that breaks it down using wp_count_posts to count the posts directly from the DB.

Alternate Designs

N/A.

Possible Drawbacks

A bit more processing during indexing if the count query has died, but at least the user will have an idea of the number of posts, rather than "0".

Verification Process

On a verrrry large site where it says 0 as the total objects, i.e. Processed x/0, apply the PR and expect it to return a number.

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

Fixed: Add an alternative way to count total posts on larger DBs during indexing

Credits

Props @rebeccahum

includes/classes/Indexable/Post/Post.php Outdated Show resolved Hide resolved
includes/classes/Indexable/Post/Post.php Show resolved Hide resolved
includes/classes/Indexable/Post/Post.php Outdated Show resolved Hide resolved
@rebeccahum
Copy link
Contributor Author

@felipeelia Thanks for your feedback! All have been addressed now.

@felipeelia felipeelia merged commit a774cae into 10up:develop Jan 28, 2022
rebeccahum added a commit to Automattic/ElasticPress that referenced this pull request Jan 28, 2022
rebeccahum added a commit to Automattic/ElasticPress that referenced this pull request Jan 28, 2022
rebeccahum added a commit to Automattic/ElasticPress that referenced this pull request Jan 28, 2022
* Mirror upstream PR 10up#2571

* Remove wild whitespace
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