Fix unbounded get_users() in theme-switch review-notice cleanup - #115
Merged
Merged
Conversation
review_notice_data_remove() called get_users() with no arguments - loading every user on the site as a full WP_User object, then doing a get_user_meta() round-trip per user - purely to delete two user-meta keys that either exist or don't. Since the code never branched on the meta's actual value (only whether it existed), there was no need to read it first at all. Replaced the whole get_users()-plus-loop with two delete_metadata() calls (delete_all = true), which delete a meta key across every user in one query each, without ever loading a single user object. Verified live via the real wp-admin theme-switch UI (this class only loads inside is_admin(), so WP-CLI's own theme-switch bootstrap doesn't exercise it): set the two meta keys on multiple users, switched away from Flash, confirmed both keys were gone for every user afterward.
QA suite — refused, no regression specThis PR changes product source but adds no spec, so the suite was Source files changed with no matching spec |
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The optimization preserves intended behavior; only a non-blocking documentation nit remains.
Review effort: Lite
Findings: None
What changed in this PR
Fixes theme-switch cleanup to avoid loading every user when removing review-notice metadata.
Changes:
- Replaces unbounded
get_users()usage with bulk metadata deletion. - Preserves removal of the installation-time option.
| File | Summary |
|---|---|
inc/admin/class-flash-theme-review-notice.php |
Optimizes cleanup; non-blocking nit: revise the comment’s query-count claim. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
Fixes themegrill/flash-pro#36
Changes proposed in this Pull Request:
review_notice_data_remove() (inc/admin/class-flash-theme-review-notice.php, hooked on switch_theme) called get_users() with no arguments - loading every user on the site as a full WP_User object, then doing a get_user_meta() round-trip per user, purely to delete two dismissal meta keys that either exist or don't. The code never branched on the meta's actual value, only whether it existed, so there was no need to read it first at all.
Replaced the whole get_users()-plus-loop with two delete_metadata( 'user', 0, $key, '', true ) calls, which delete a meta key across every user in one query each, without ever loading a single user object.
Verification note: this class only loads inside is_admin(), so it can't be exercised via a plain front-end visit or WP-CLI's own theme-switch command - had to verify via the real wp-admin theme-switch UI instead. Set both meta keys on multiple users, switched away from Flash through that UI, confirmed both keys were gone for every user afterward.
How to test the changes in this Pull Request:
Types of changes:
Other information:
Changelog entry
Fix - Theme-switch cleanup no longer loads every user on the site to delete two dismissal meta keys.