Connection: seed jetpack_tos_agreed to avoid per-request reads - #50965
Draft
darssen wants to merge 1 commit into
Draft
Connection: seed jetpack_tos_agreed to avoid per-request reads#50965darssen wants to merge 1 commit into
darssen wants to merge 1 commit into
Conversation
`Terms_Of_Service::get_raw_has_agreed()` reads `jetpack_tos_agreed` whenever tracking is evaluated (Tracks events, tracking-script enqueues, Jetpack admin pages). On sites without a persistent object cache, when the option is absent this is a dedicated `SELECT` on each such request. Seed an autoloaded default (via `add_option`, using a `null` sentinel to tell "never stored" apart from a stored `false`) so the value rides the bulk `alloptions` load. Not synced; behaviour unchanged (an unset option already resolved to `false`, a stored value still wins). Includes a real options-table `Terms_Of_Service_Seeding_Test`. Opening for discussion of the tracking-gate semantics — see the PR description.
darssen
added a commit
that referenced
this pull request
Jul 31, 2026
The tos_agreed seed raises a separate tracking-gate question, so it's split into #50965. This PR now covers only jetpack_offline_mode (Status package).
Contributor
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
Contributor
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! |
Code Coverage SummaryCoverage changed in 1 file.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed changes
Terms_Of_Service::get_raw_has_agreed(): whenjetpack_tos_agreedis absent, seed it as an autoloadedfalse(viaadd_option, using anullsentinel to distinguish "never stored" from a storedfalse), so it isn't re-queried every time it's read.Terms_Of_Service_Seeding_Testcovering absent → seed (autoloaded) and stored → not re-seeded.Why are these changes being made
On a site without a persistent object cache, WP's per-request option caches (
alloptions/notoptions) are discarded each request, so a non-autoloaded option costs a dedicatedSELECT … FROM wp_optionseach time it's read.jetpack_tos_agreedis read viaTerms_Of_Service::has_agreed(), which fires whenever tracking is evaluated — Tracks events, tracking-script enqueues, and Jetpack admin pages (e.g. the dashboard). When the option is absent, each of those requests re-reads a missing option. Seeding an autoloaded default on the first miss moves it into the single bulkalloptionsload. It's not synced, and behaviour is unchanged (an unset option already resolved tofalse; a stored value still wins and is never overwritten).Open question — is seeding
falsethe right call, or should the tracking gate change?This is why it's split out from the
jetpack_offline_modechange (#50961) and opened for discussion.jetpack_tos_agreedhas exactly one writer:Connection\Manager::try_registration()→Terms_Of_Service::agree()— the plugin-driven site-registration step. A site connected through any other path (platform/host-level provisioning, CLI, partner/pre-provisioned tokens, or connections predating the option) never runs it, sohas_agreed()isfalseeven though the site is fully connected. On those sites the option is legitimately absent, which is what makes it re-read.That exposes an inconsistency between the two tracking gates:
Tracking::should_enable_tracking()→! is_offline_mode() && ( has_agreed() || is_user_connected() )— tolerant: a connected user is enough.Jetpack_Tracks_Client::record_event()→ strict:if ( ! has_agreed() || opt-out ) return false;— nois_user_connected()fallback.So on a connected-but-unregistered site,
should_enable_tracking()says "track" whilerecord_event()silently drops server-side events.Questions for reviewers:
jetpack_tos_agreedeven gate these sites, or does an active connection already imply agreement? (i.e. isfalsethe correct value to seed, or is the real issue that it should betrue/ not consulted?)Jetpack_Tracks_Client::record_event()use the same|| is_user_connected()fallback asshould_enable_tracking(), so the two gates agree?The seed here is the minimal, behaviour-preserving option (it removes the repeat read without changing any tracking outcome), but it papers over the above rather than resolving it.
Related product discussion/links
Does this pull request change what data or activity we track or use?
No. Seeding writes the existing default value (
false) to the local options table;has_agreed()returns the same result as before, so no tracking behaviour changes. Not synced to WordPress.com.Testing instructions
Use a site with no persistent object cache (on jurassic.ninja, create it with "Drop-in Cache Plugins" unchecked; confirm
wp eval 'var_dump( wp_using_ext_object_cache() );'isfalse).Add a logger mu-plugin (
wp-content/mu-plugins/tos-check.php):jetpack_tos_agreedis not read on plain front-end requests — exercise it from wp-admin: log in and reload the Jetpack dashboard (or any wp-admin page) a few times, thencat wp-content/tos.log.SELECT … 'jetpack_tos_agreed'per admin page load.wp db query "SELECT option_name, autoload FROM wp_options WHERE option_name = 'jetpack_tos_agreed'"→autoload = on.Terms_Of_Service::has_agreed()still reflects stored TOS state; a value set beforehand is never overwritten.Unit tests:
projects/packages/connection—Terms_Of_Service_Seeding_Test.