BenchmarkFetcher
\Benecaster\Analytics\BenchmarkFetcher
Fetches platform benchmark statistics from the license server and caches them per license for 24 hours, in the transient benecaster_benchmark_data_l{license_id} (_s{show_uuid} when the show has no stored license ID). The license server compares each license with shows on its own plan, and the shows on a license share its cache. The dashboard and REST handlers read a show’s payload through get( $show_id ); the daily cron refreshes every connected license, and the analytics REST controller’s lazy refresh fetches only the viewed show’s.
Eligibility has two conditions and neither is a license 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: a show with no stored token is skipped, and get() returns null for it rather than another license’s figures. The outbound call is GET /analytics/benchmarks with an empty query string and an Authorization: Bearer <show 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 connected show UUIDs, their tokens and their license IDs. Defaults to a new instance. |
Methods
| Method | Visibility | Since | Description |
|---|---|---|---|
get( int $show_id = 0 ): ?array |
Public | — | Reads the cached benchmark payload for that show's license, or null when no cached data exists or the show has no stored token. 0 reads the first connected show's. Never triggers a fetch — callers that want to populate an empty cache must invoke refresh() first. |
refresh( string $source = 'manual', int $show_id = 0 ): bool |
Public | — | Fetches fresh payloads and writes each license's cache, returning true when at least one was written. With a $show_id, fetches for that show's license only; with 0, fetches once per connected license (shows sharing a license share one fetch). Applies the benecaster_benchmarks_fetch_skip filter, then should_fetch(). Fires benecaster_benchmarks_refreshed once per cache written. A failed fetch leaves that license's existing cache intact. $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 license status or any license key. |
Constants
| Name | Value | Description |
|---|---|---|
TRANSIENT |
'benecaster_benchmark_data' |
Prefix of the per-license transient keys: {TRANSIENT}_l{license_id}, or {TRANSIENT}_s{show_uuid} when no license ID is stored. A transient under the bare key is a leftover and is deleted on the next refresh. |
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
Notes
Read this before changing the skip rules. should_fetch() has no license-key check. On an
OAuth-connected install that option is always empty, so a license-key gate would mean benchmark
data never fetches at all on any correctly-connected site. Do not add a license-key check.
There is no BenchmarkFetcher::OPTION_KEY constant. The public constants are TRANSIENT,
TRANSIENT_TTL and OPTION_OPT_IN.
LicenseValidationCron::send_vendor_alert() and the diagnostic log sender follow the same
rule.