Skip to content

Commit

Permalink
Process Follower Inboxes in Batches (Automattic#1262)
Browse files Browse the repository at this point in the history
* First pass at batching

* Make it "work"

* Updated approach

* Make it work

* Account for in-progress batches when reprocessing

* Fix tests

* Update phpdocs

* Add/sent to inboxes actions (Automattic#1278)

* add some actions

* fix phpdoc

* Use "Unreleased" instead of version number

* Add readme

* Switch actions

props @obenland

* renamed action names

* fix phpdoc

* fix phpdoc

* fix phpdoc

* fix namings

* fix phpcs issues

* Update function to account for new audience

Also re-uses the `activitypub_sent_to_inbox` action

* Always notify interactees

Props @pfefferle

* Use customizable constant for batch size

* Publish post after processing interactees if they don't get sent to followers

* use outbox processing instead

* change filter name

* Don't change function signature

* Revert unnecessary docs change

* use `apply_filters_deprecated` instead

* fix apply_filters_deprecated

* only log errors

* store object id as meta

* better php doc

* Add test for deprecated filter

* Keep track of where we are in each batch

Allows the reprocess job to skip already processed batches

* Revert object id meta

We'll do that in a separate PR

* Add tests for new Followers methods

* Register meta

* With meta now registered, it shouldn't need a fallback

* Stream: Only surface errors in Outbox processing (Automattic#1240)

* Stream: Only surface errors in Outbox processing

Also adds support for comment and user types.

* Add changelog

* fix readme

* update to new batch processing

* fix phpcs

* fix phpcs

* re-use wordings from the rest controllers

* fix phpcs

* restructure the output to match the errors

* revert latest changes

* Fixed changelog

---------

Co-authored-by: Matthias Pfefferle <[email protected]>

* Move publish_post to calling function

Makes it a bit easier to see what's happening when reading the code.

* Help future devs

* No longer needed

* Restore fallback for tests

* Outbox Batch: Only pass outbox id to jobs (Automattic#1285)

* Outbox Batch: Only pass outbox id to jobs

* Remove unnecessary imports

---------

Co-authored-by: Matthias Pfefferle <[email protected]>
  • Loading branch information
obenland and pfefferle authored Feb 7, 2025
1 parent a02be9c commit 272ba8e
Show file tree
Hide file tree
Showing 11 changed files with 829 additions and 206 deletions.
9 changes: 5 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

* Batch Outbox-Processing.
* Outbox processed events get logged in Stream and show any errors returned from inboxes.

### Changed

* Increased probability of Outbox items being processed with the correct author.
Expand Down Expand Up @@ -65,10 +70,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* Support for WPML post locale

### Added

* Outbox queue

### Changed

* Rewrite the current dispatcher system, to use the Outbox instead of the Scheduler.
Expand Down
12 changes: 12 additions & 0 deletions includes/class-activitypub.php
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,18 @@ private static function register_post_types() {
)
);

\register_post_meta(
Outbox::POST_TYPE,
'_activitypub_outbox_offset',
array(
'type' => 'integer',
'single' => true,
'description' => 'Keeps track of the followers offset when processing outbox items.',
'sanitize_callback' => 'absint',
'default' => 0,
)
);

\register_post_meta(
Outbox::POST_TYPE,
'activitypub_content_visibility',
Expand Down
20 changes: 16 additions & 4 deletions includes/class-debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@

namespace Activitypub;

use WP_DEBUG;
use WP_DEBUG_LOG;

/**
* ActivityPub Debug Class.
*
Expand All @@ -20,9 +17,11 @@ class Debug {
* Initialize the class, registering WordPress hooks.
*/
public static function init() {
if ( WP_DEBUG_LOG ) {
if ( \WP_DEBUG && \WP_DEBUG_LOG ) {
\add_action( 'activitypub_safe_remote_post_response', array( self::class, 'log_remote_post_responses' ), 10, 2 );
\add_action( 'activitypub_inbox', array( self::class, 'log_inbox' ), 10, 3 );

\add_action( 'activitypub_sent_to_inbox', array( self::class, 'log_sent_to_inbox' ), 10, 2 );
}
}

Expand Down Expand Up @@ -55,6 +54,19 @@ public static function log_inbox( $data, $user_id, $type ) {
}
}

/**
* Log the sent to follower action.
*
* @param array $result The result of the remote post request.
* @param string $inbox The inbox URL.
*/
public static function log_sent_to_inbox( $result, $inbox ) {
if ( \is_wp_error( $result ) ) {
// phpcs:ignore WordPress.PHP.DevelopmentFunctions
\error_log( "[DISPATCHER] Failed Request to: {$inbox} with Result: " . \print_r( $result, true ) );
}
}

/**
* Write a log entry.
*
Expand Down
Loading

0 comments on commit 272ba8e

Please sign in to comment.