Skip to content

perf: avoid redundant admin statistics counts - #1155

Merged
mostafasoufi merged 3 commits into
wp-statistics:developmentfrom
superdav42:perf/redundant-admin-counts
Oct 9, 2026
Merged

mostafasoufi merged 3 commits into
wp-statistics:developmentfrom
superdav42:perf/redundant-admin-counts

Conversation

@superdav42

Copy link
Copy Markdown
Contributor

Summary

Avoid two forms of redundant metric work, without adding a persistent cache:

  • src/Service/Admin/Posts/HitColumnHandler.php: total-view mode currently calls countViewsFromPagesOnly() twice and overwrites the first result. Call only the historical-aware branch in total mode, preserving its arguments and output. Other view modes and visitor counts are unchanged.
  • includes/class-wp-statistics-admin-bar.php: reuse this render's online/today/yesterday metrics between the toolbar HTML and wp_statistics_admin_bar filter data. Each metric is resolved once rather than twice; formatting and filter arguments are unchanged.

Verification

  • Applied against current upstream master (38e82ae, 14.16.15).
  • Both changed files pass php -l; git diff --check passes.
  • Disposable isolated semantic probe: 24 combinations of disabled/date-range/total display, views/visitors, posts/terms and term-link errors retain identical values and final model arguments. Total-view mode performs one aggregate rather than two.
  • Toolbar menu structures and filter data match the original byte-for-byte; online and each daily metric resolve once instead of twice.
  • Earlier real authenticated local WordPress replay with the same fix preserved actual column HTML and toolbar data. A 20-row Pages screen removed 40 redundant column queries plus three duplicate toolbar queries. These counts are not production latency claims.

Full WordPress PHPUnit suite was not run. Configured PHPCS reports extensive existing formatting violations in these files; a clean lint result is not claimed. No generated assets, scratch reports or test infrastructure are included. Draft for maintainer review.


aidevops.sh v3.34.13 plugin for OpenCode v1.18.31 with gpt-6.1-sol

@mostafasoufi
mostafasoufi changed the base branch from master to development October 9, 2026 06:08
@mostafasoufi
mostafasoufi marked this pull request as ready for review October 9, 2026 06:08
@mostafasoufi

Copy link
Copy Markdown
Member

Thanks for this, the change is clean and the numbers check out: the second countViewsFromPagesOnly() call in total mode was a throw-away, and the admin bar metrics were queried twice per render.

We moved the PR to development (that's where we merge fixes) and we'll add the changelog line ourselves, so there's nothing more for you to do. It will ship in the next release.

mostafasoufi added a commit that referenced this pull request Oct 9, 2026
@aria-veronalabs

aria-veronalabs commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Aria QA — complete

Verdict: No net-new correctness, security, or regression issues. No follow-up commit was needed.

What I verified

  • The hit-column change preserves total/date-range/disabled behavior while reducing total-view mode from two countViewsFromPagesOnly() calls to one.
  • The admin-bar change resolves online/today/yesterday metrics once and reuses the same values in both menu HTML and wp_statistics_admin_bar filter data.
  • Focused mutation-checked probes passed on a3c076a; both probes failed against the pre-change merge base for the intended reason (duplicate calls).
  • php -l passed for both changed PHP files, git diff --check passed, and the existing PHP 7.4–8.5 CI matrix is green.

Fixed

  • Nothing: the reviewed branch already implements the requested optimization correctly, so I did not add a speculative follow-up commit.

Deliberately left

  • No persistent cache, broader query refactor, or unrelated legacy style cleanup.
  • No changelog change on the contributor branch; the maintainer already added the #1155 changelog entry to development in 13a896c.

Author decision needed

  • None.

I did not merge or approve the PR.

@mostafasoufi
mostafasoufi merged commit 514f877 into wp-statistics:development Oct 9, 2026
8 checks passed
@mostafasoufi mostafasoufi mentioned this pull request Oct 9, 2026
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.

3 participants