Skip to content

Conversation

@dkoo
Copy link
Contributor

@dkoo dkoo commented Jan 23, 2026

All Submissions:

Changes proposed in this Pull Request:

Plugs a performance hole by memoizing the result of Metering_Countdown::is_enabled() to avoid redundant checks that can cause extra calculations and site slowdowns.

#2243 proposes some additional improvements that are worth making for content gating logic, but this PR should hotfix a known performance issue for live sites already using metered content gates.

Closes NPPM-2543.

How to test the changes in this Pull Request:

  1. On release, add an error_log( 'post is not metered or restricted' ); after line 138 and visit a post that's NOT affected by content gating rules. Observe that your test error log is logged many times for the single page request, demonstrating that this method is running a lot more often than needed.
  2. Check out this branch and repeat, and confirm that the error log appears only once per page request.
  3. Smoke test countdown banner functionality to make sure it still works as described in fix: select specific product for content gifting and countdown banners #4366.

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?

@dkoo dkoo changed the base branch from trunk to release January 23, 2026 23:34
@dkoo dkoo self-assigned this Jan 23, 2026
@dkoo dkoo added the [Status] Needs Review The issue or pull request needs to be reviewed label Jan 23, 2026
@dkoo dkoo marked this pull request as ready for review January 23, 2026 23:37
@dkoo dkoo requested a review from a team as a code owner January 23, 2026 23:37
Copilot AI review requested due to automatic review settings January 23, 2026 23:37
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR implements caching for the Metering_Countdown::is_enabled() method to address a performance issue where the method was being called redundantly during a single page request, causing unnecessary computations on live sites using metered content gates.

Changes:

  • Added a static property $is_enabled to cache the result of the enabled check
  • Modified is_enabled() to return the cached value on subsequent calls within the same request
  • All code paths properly set and return the cached boolean value

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

if ( $enabled && is_customize_preview() ) {
return true;
if ( self::$is_enabled && is_customize_preview() ) {
self::$is_enabled = true;
Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

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

The assignment on line 144 is redundant. Since self::$is_enabled is already true (from the condition on line 143), there's no need to set it to true again before returning. You can simply return self::$is_enabled or even just return true directly. The same applies to lines 150-151 where the value is set to false unnecessarily.

Suggested change
self::$is_enabled = true;

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Status] Needs Review The issue or pull request needs to be reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants