Add configurable distribution modes for federation delivery#3044
Draft
Add configurable distribution modes for federation delivery#3044
Conversation
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
There was a problem hiding this comment.
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_sizeandactivitypub_scheduler_async_batch_pause. - Adds
ACTIVITYPUB_DISTRIBUTION_MODEconstant 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.
Comment on lines
+33
to
+41
| if ( ! ACTIVITYPUB_DISTRIBUTION_MODE ) { | ||
| \add_settings_field( | ||
| 'activitypub_distribution_mode', | ||
| \__( 'Distribution Mode', 'activitypub' ), | ||
| array( self::class, 'render_distribution_mode_field' ), | ||
| 'activitypub_advanced_settings', | ||
| 'activitypub_advanced_settings' | ||
| ); | ||
| } |
Comment on lines
+692
to
+698
| public static function pre_option_activitypub_distribution_mode( $pre ) { | ||
| if ( false !== ACTIVITYPUB_DISTRIBUTION_MODE ) { | ||
| return ACTIVITYPUB_DISTRIBUTION_MODE; | ||
| } | ||
|
|
||
| return $pre; | ||
| } |
Comment on lines
+707
to
+723
| public static function get_distribution_params() { | ||
| $mode = \get_option( 'activitypub_distribution_mode', 'default' ); | ||
|
|
||
| $modes = array( | ||
| 'default' => array( | ||
| 'batch_size' => 100, | ||
| 'pause' => 30, | ||
| ), | ||
| 'balanced' => array( | ||
| 'batch_size' => 50, | ||
| 'pause' => 60, | ||
| ), | ||
| 'eco' => array( | ||
| 'batch_size' => 20, | ||
| 'pause' => 300, | ||
| ), | ||
| ); |
Comment on lines
+745
to
+748
| public static function filter_dispatcher_batch_size( $batch_size ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found, VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable | ||
| $params = self::get_distribution_params(); | ||
| return $params['batch_size']; | ||
| } |
Comment on lines
+759
to
+762
| public static function filter_scheduler_batch_pause( $pause ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found, VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable | ||
| $params = self::get_distribution_params(); | ||
| return $params['pause']; | ||
| } |
Comment on lines
+370
to
+380
| <script> | ||
| ( function() { | ||
| var radios = document.querySelectorAll( 'input[name="activitypub_distribution_mode"]' ); | ||
| var fields = document.getElementById( 'activitypub-custom-distribution-fields' ); | ||
| radios.forEach( function( radio ) { | ||
| radio.addEventListener( 'change', function() { | ||
| fields.style.display = this.value === 'custom' ? '' : 'none'; | ||
| } ); | ||
| } ); | ||
| } )(); | ||
| </script> |
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.
Fixes #2672
Proposed changes:
activitypub_dispatcher_batch_sizeandactivitypub_scheduler_async_batch_pausefilters so admins can tune federation delivery speed without code.ACTIVITYPUB_DISTRIBUTION_MODEconstant for wp-config.php override (hides the UI when set).Other information:
Testing instructions:
ACTIVITYPUB_DISTRIBUTION_MODEas'eco'in wp-config.php — verify the UI field is hidden and Eco mode values are used.Changelog entry
Changelog Entry Details
Significance
Type
Message
Add a Distribution Mode setting to control how quickly posts are delivered to followers.