BenchmarkFetcher
\Benecaster\Analytics\BenchmarkFetcher
Fetches platform benchmark statistics from the license server and caches the response in the benecaster_benchmark_data transient for 24 hours. The dashboard and REST handlers read the cached payload through get(); the daily cron and a lazy refresh from the analytics REST controller drive refresh().
Eligibility has two conditions and neither is a licence key. should_fetch() checks telemetry opt-in and nothing else — the license server computes benchmarks only from opted-in installs, so a site that does not contribute gets no useful payload. The connection requirement is enforced inside refresh(), which needs a per-show bearer token to send: if no show on the site has a token, the fetch is skipped. The outbound call is GET /analytics/benchmarks with an empty query string and an Authorization: Bearer <site token> header.
On any HTTP failure the existing cached payload is left intact, so a flapping endpoint does not blank the dashboard panel. Skip rules likewise return false without clearing the transient — a dropped opt-in does not wipe a yesterday-fresh cache mid-session.
Constructor Dependencies
| Type | Description |
|---|---|
\Benecaster\License\LicenseClient |
Issues the authenticated GET to the license server. |
\Benecaster\License\ShowTokenRepository |
Supplies the list of connected show UUIDs; the first one authenticates the call. Defaults to a new instance. |
Methods
| Method | Visibility | Since | Description |
|---|---|---|---|
get(): ?array |
Public | — | Reads the cached benchmark payload, or null when no cached data exists. Never triggers a fetch — callers that want to populate an empty cache must invoke refresh() first. |
refresh( string $source = 'manual' ): bool |
Public | — | Fetches a fresh payload and writes the transient on success, returning true. Applies the benecaster_benchmarks_fetch_skip filter, then should_fetch(), then the connected-show check. Fires benecaster_benchmarks_refreshed on success. $source is passed to the skip filter so add-ons can tell a cron refresh from a lazy on-demand one. |
should_fetch(): bool |
Public | — | Whether the install is eligible to call the benchmarks endpoint. Telemetry opt-in is the only condition. Does not consult licence status or any licence key. |
Constants
| Name | Value | Description |
|---|---|---|
TRANSIENT |
'benecaster_benchmark_data' |
Transient key holding the cached benchmark payload. |
TRANSIENT_TTL |
DAY_IN_SECONDS |
Cache lifetime for the benchmark payload. |
OPTION_OPT_IN |
'benecaster_telemetry_opted_in' |
Option consulted by should_fetch(). |
Hooks Fired
-
benecaster-benchmarks-refreshed
Notes
**Behaviour change (feature/retire-legacy-license-key, 2026-08-31) — read this before changing the
skip rules.** should_fetch() used to return false on an empty benecaster_license_key. On an
OAuth-connected install — every install created since the OAuth pivot — that option is always empty,
so benchmark data never fetched at all on any correctly-connected site. Removing the gate means
benchmarks now populate where they previously could not. Do not re-add a licence-key check.
The public constant BenchmarkFetcher::OPTION_KEY was removed in the same change. It existed only
to hold benecaster_license_key. TRANSIENT, TRANSIENT_TTL and OPTION_OPT_IN are unchanged.
Same gate, same cause and same fix as LicenseValidationCron::send_vendor_alert() and
DiagnosticLogSender::send().