Automattic / Automattic/jetpack

PBE: Improve options handling

Open
#35,636 2 comments 0 reactions 0 assignees View on GitHub
[Feature] Post By Email [Focus] Performance [Plugin] Jetpack [Pri] Low Bug Good For Community Triaged
Dominant language
PHP
Stars
1.8k
Forks
898
Avg merge
1d 18h
Merged PRs (30d)
774

Description

### Impacted plugin

Jetpack

### Quick summary

- Post-by-email creates an autoloaded `post_by_email_addressX` option (where X is the user's ID) **for every user** that sees the JP settings page in wp-admin, _even if the user doesn't use the feature_, in which case the option's value is `NULL`.
- Creation of these options may occur in other scenarios too, but this is the easiest way to verify & replicate that isn't edge-case.
- Can bloat a lot at scale! Instances as high as `post_by_email_address149154895` have been observed.
- These options don't get any cleanup/housekeeping, and `post_by_email_addressX` options have been observed lingering around for long-deleted user IDs.

### Steps to reproduce

1. Login to a JP-connected site
2. CLI `wp option list --search="post_by_email*" --fields=option_name,option_value,autoload`
3. Look for a `post_by_email_addressX` option whose number matches your user ID
4. If it's not there, observe the JP settings in wp-admin
5. Check for option again; it will have been created by step 4
6. (optional) delete the option, redo step 4, verify it respawns

### A clear and concise description of what you expected to happen.

**No `NULL` option creation, no autoload!**
- We shouldn't create the option at all unless the user is actively using the PBE feature - just store an option for users that have it set up, and store no option for those that don't. Any existing checks for this value being null can simply be replaced for checks to see if the option _exists_ instead.
- Even when one of these options is populated (with non-null), the option isn't required by WP _until a PBE email happens_, so it doesn't need autoloading, not being needed at all for the vast majority of WP loads.

### What actually happened

A `post_by_email_addressX` option is created for the user ID of any user that sees the JP settings (and possibly other scenarios) even if they don't have the PBE feature set up / connected to WPCOM.

### Impact

All

### Available workarounds?

Yes, easy to implement

### Platform (Simple and/or Atomic)

_No response_

### Logs or notes

_No response_

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the issue with `wp option list --search="post_by_email*" --fields=option_name,option_value,autoload`, then trace where Jetpack's Post-by-email settings page creates `post_by_email_addressX` options. Done means unused users create no NULL option, populated options are not autoloaded, and checks distinguish an existing option from a NULL value.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.