Skip to content

Stop loading every user to clear the dismissed review notice flags on theme switch - #94

Open
deepench wants to merge 1 commit into
developfrom
fix/theme-switch-user-cleanup
Open

deepench wants to merge 1 commit into
developfrom
fix/theme-switch-user-cleanup

Conversation

@deepench

@deepench deepench commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Free-theme counterpart of themegrill/accelerate-pro#26 (the same pattern is in the free review notice).

Changes proposed in this Pull Request:

On switch_theme, review_notice_data_remove() called get_users() with no arguments, which builds a WP_User object and loads the meta for every user, only to find the few who dismissed the review notice. It now asks for just the IDs of users that have each flag (accelerate_ignore_theme_review_notice and nag_accelerate_ignore_theme_review_notice_partially) and deletes it for those. It is still limited to the current site's users, as before. The accelerate_theme_installed_time option cleanup is unchanged.

The issue says there is no GitHub repo for the free theme, but this one exists. It also estimates two queries per user; WordPress primes the user meta cache in bulk inside get_users(), so the real cost is memory and object building, not per-user queries. I did not use the suggested delete_metadata( 'user', 0, $key, '', true ) because user meta is shared across a multisite network, so it would clear the flags for users on every site, not just the current one.

Measured on a local site with 131 users (a temporary mock, since removed):

Before After
Peak extra memory 1731 KB 508 KB
Queries, nothing flagged 5 4
Queries, 8 users flagged (12 rows) 29 28
Flagged rows after cleanup 0 0
Other user meta untouched untouched

PHPCS on the changed file shows no new violations (3 to 2 errors). The new meta_key lookup carries a one-line phpcs:ignore with the reason: it is indexed and runs once per theme switch.

How to test the changes in this Pull Request:

  1. On a site with several users, dismiss the theme review notice (permanently or with "remind me later") as a few of them.
  2. Switch to another theme.
  3. Check the usermeta table: no accelerate_ignore_theme_review_notice or nag_accelerate_ignore_theme_review_notice_partially rows remain, and other user meta is unchanged.

Types of changes:

  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (modification of the currently available functionality)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Other information:

  • Have you added an explanation of what your changes do and why you would like us to include them?
  • Have you successfully ran tests with your changes locally?
  • Have you updated the documentation accordingly?

Changelog entry

Fix - Theme switch no longer loads every user to clear dismissed notice flags.

… theme switch

review_notice_data_remove() called get_users() with no arguments, which builds
a user object and loads the meta for every user just to find the few who
dismissed the notice. It now asks only for the IDs of users who have each flag
and deletes it for those, scoped to the current site as before.

Verified with 131 users: peak extra memory dropped from about 1.7 MB to about
0.5 MB with the same number of queries when users are flagged; all flagged rows
are removed and other meta is left alone.
@deepench deepench added the bug label Oct 1, 2026
@tg-autopilot
tg-autopilot requested a lite review from Copilot October 1, 2026 07:18
@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown

QA suite — refused, no regression spec

This PR changes product source but adds no spec, so the suite was
refused before booting WordPress — running it just to report the same
thing at the end costs runner minutes for nothing. Run
/claudegrill:verify-fix locally and let write-spec add the guard
to this branch, then push again.

Source files changed with no matching spec
inc/admin/class-accelerate-theme-review-notice.php

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

No unresolved issues were identified.

Review effort: Lite
Findings: None

What changed in this PR

Optimizes theme-switch cleanup by querying only users with review-notice dismissal metadata instead of loading every user.

Changes:

  • Targets matching user IDs for cleanup.
  • Preserves site scope and option cleanup.
  • Leaves unrelated user metadata untouched.
File Summary
inc/​admin/​class-accelerate-theme-review-notice.php Uses targeted user-ID queries for notice metadata cleanup.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants