Fix wp site empty O(n) scaling: replace per-item cache ops with wp_cache_flush()#601
Open
Fix wp site empty O(n) scaling: replace per-item cache ops with wp_cache_flush()#601
wp site empty O(n) scaling: replace per-item cache ops with wp_cache_flush()#601Conversation
…lush() Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] [Bug Report] Fix scaling issue with wp site empty command
Fix Mar 17, 2026
wp site empty O(n) scaling: replace per-item cache ops with wp_cache_flush()
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
…hildren options Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Optimizes wp site empty to avoid O(n) behavior on large sites by removing per-object cache operations and unbounded ID fetches, relying instead on direct table truncation and a single cache flush.
Changes:
- Remove per-comment and per-post ID iteration/cache deletions; truncate content tables directly.
- Simplify link deletion to a direct links table truncation.
- Add a single
wp_cache_flush()at the end and update the command docblock accordingly.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
wp site emptyscaled linearly with object count due to per-item cache deletions before each table truncation.empty_comments()also issued an unboundedSELECT comment_IDquery, risking memory exhaustion on large sites.Changes
empty_comments()— removed unboundedget_col()fetch and per-itemwp_cache_delete()loop; now truncates directlyempty_posts()— removedQueryIteratorloop over all post IDs for cache eviction; now truncates directlyempty_taxonomies()— usesget_taxonomies()(registered taxonomies, no DB read) instead of scanning theterm_taxonomytable; consolidates alldelete_option("{$taxonomy}_children")calls into a singleDELETE FROM {$wpdb->options} WHERE option_name IN (...)queryempty_links()— removedQueryIteratorloop withwp_delete_object_term_relationships()/clean_object_term_cache()per link; now truncates directlyempty_()— callswp_cache_flush()once after all truncations, replacing all the per-item evictions with a single O(1) cache flushQueryIteratorimportOriginal prompt
💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.