Skip to content

Add configurable distribution modes for federation delivery#3044

Open
pfefferle wants to merge 10 commits intotrunkfrom
add/distribution-mode-setting
Open

Add configurable distribution modes for federation delivery#3044
pfefferle wants to merge 10 commits intotrunkfrom
add/distribution-mode-setting

Conversation

@pfefferle
Copy link
Copy Markdown
Member

Fixes #2672

Proposed changes:

  • Add a "Distribution Mode" setting to the Advanced Settings page with four presets: Default (100/batch, 30s pause), Balanced (50/batch, 60s pause), Eco (20/batch, 5min pause), and Custom (manual configuration).
  • Wire the presets into the existing activitypub_dispatcher_batch_size and activitypub_scheduler_async_batch_pause filters so admins can tune federation delivery speed without code.
  • Add ACTIVITYPUB_DISTRIBUTION_MODE constant for wp-config.php override (hides the UI when set).

Other information:

  • Have you written new tests for your changes, if applicable?

Testing instructions:

  • Go to Settings > ActivityPub > Advanced.
  • Verify the "Distribution Mode" setting appears as the first field.
  • Select each mode (Default, Balanced, Eco, Custom) and save — verify the page reloads with the correct selection preserved.
  • Select "Custom", enter custom values for batch size and pause, save — verify the values are preserved.
  • Verify the Custom fields toggle visibility when switching between Custom and other modes.
  • Define ACTIVITYPUB_DISTRIBUTION_MODE as 'eco' in wp-config.php — verify the UI field is hidden and Eco mode values are used.

Changelog entry

  • Automatically create a changelog entry from the details below.
Changelog Entry Details

Significance

  • Patch

Type

  • Added - for new features

Message

Add a Distribution Mode setting to control how quickly posts are delivered to followers.

Adds a "Distribution Mode" setting to the Advanced Settings page with
four presets (Default, Balanced, Eco, Custom) that control batch size
and pause between batches for federation delivery. Includes a constant
override via ACTIVITYPUB_DISTRIBUTION_MODE in wp-config.php.

Fixes #2672
Copilot AI review requested due to automatic review settings March 17, 2026 09:56
@pfefferle pfefferle added the Enhancement New feature or request label Mar 17, 2026
@pfefferle pfefferle self-assigned this Mar 17, 2026
@pfefferle pfefferle requested a review from a team March 17, 2026 09:56
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an admin-configurable “Distribution Mode” that controls federation delivery pacing via existing dispatcher/scheduler filters, with an optional wp-config.php constant override to enforce a mode and hide the UI.

Changes:

  • Adds an Advanced Settings “Distribution Mode” radio field with presets and custom batch/pause inputs.
  • Registers new options and wires delivery pacing into activitypub_dispatcher_batch_size and activitypub_scheduler_async_batch_pause.
  • Adds ACTIVITYPUB_DISTRIBUTION_MODE constant override and a changelog entry.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.

File Description
includes/wp-admin/class-advanced-settings-fields.php Adds the Distribution Mode settings UI, including custom input toggling.
includes/constants.php Defines ACTIVITYPUB_DISTRIBUTION_MODE for wp-config.php overrides.
includes/class-options.php Registers new settings and applies distribution mode to existing delivery pacing filters.
.github/changelog/3044-from-description Records the feature in the changelog.

You can also share your feedback on Copilot code review. Take the survey.

@pfefferle pfefferle marked this pull request as draft March 17, 2026 10:21
@pfefferle pfefferle marked this pull request as draft March 17, 2026 10:21
- Fix inconsistent constant check: use `false ===` in both the UI
  visibility check and the option override
- Validate ACTIVITYPUB_DISTRIBUTION_MODE constant against allowed
  modes, falling back to 'default' for invalid values
- Centralize preset definitions in Options::get_distribution_modes()
  and reuse in both admin UI and parameter resolution
- Add static cache in get_distribution_params() to avoid rebuilding
  presets on every filter call during delivery
- Null-guard the custom fields DOM element in inline script
Use `use` statements at the top of files instead of inline
fully-qualified class names like \Activitypub\Options::method().
@github-actions github-actions bot added the Docs label Mar 30, 2026
- Prevent batch size of 0 with max(1, absint()) sanitization.
- Default mode now passes through the incoming filter value so other
  plugins and constants are not silently overridden.
- Remove static cache from get_distribution_params() since get_option()
  is already cached by WordPress and the static var caused stale values.
- Add tests for presets, custom mode, sanitization, and filter behavior.
…stant

- Cap custom batch size at 500 and pause at 3600s to prevent
  accidental server overload via misconfiguration.
- Reject 'custom' as a valid ACTIVITYPUB_DISTRIBUTION_MODE constant
  value since its parameters are still DB-settable.
- Add tests for upper bound enforcement.
@pfefferle pfefferle marked this pull request as ready for review April 2, 2026 06:53
Default 15s, Balanced 30s, Eco 30s — the differentiation between
modes is now purely batch size (100/50/20). The previous 5min Eco
pause caused unreasonably long delivery times.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add configurable distribution modes for federation delivery

3 participants