Skip to content

Rework Follower Structure #1759

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 77 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
04ba28c
Update how the plugin stores Followers
pfefferle May 23, 2025
6c72555
du not change migration test
pfefferle May 23, 2025
3ca7292
Add tests
pfefferle May 23, 2025
9cc2842
Add changelog
matticbot May 23, 2025
2bedfd0
Merge branch 'trunk' into update/follower-db-structure
pfefferle May 26, 2025
54a9665
Merge branch 'trunk' into update/follower-db-structure
pfefferle May 26, 2025
f3292b1
Merge branch 'trunk' into update/follower-db-structure
pfefferle May 27, 2025
cba65fa
rename meta key
pfefferle May 27, 2025
ed7c368
Merge branch 'trunk' into update/follower-db-structure
pfefferle May 28, 2025
4af2b05
Merge branch 'trunk' into update/follower-db-structure
pfefferle May 28, 2025
e3e53b0
Use Actor as the new home for the POST_TYPE const
obenland May 28, 2025
0f7ebf8
Revert "Use Actor as the new home for the POST_TYPE const"
pfefferle May 30, 2025
a405043
add post type to collection
pfefferle May 30, 2025
20a1c9d
Change: Use `post_content` to store Activity-JSON
pfefferle May 30, 2025
d73d140
Add migration and tests
pfefferle May 30, 2025
189937b
Merge branch 'trunk' into change/storage-schema
pfefferle Jun 2, 2025
225f044
Add changelog
matticbot Jun 2, 2025
e0c5613
Update includes/class-migration.php
pfefferle Jun 2, 2025
ae7eb93
Update tests/includes/collection/class-test-followers.php
pfefferle Jun 2, 2025
f28e411
fix phpcs
pfefferle Jun 2, 2025
a333e8d
fix phpcs
pfefferle Jun 2, 2025
5fd693c
improve phpdoc
pfefferle Jun 2, 2025
244b3eb
fix test
pfefferle Jun 2, 2025
d30a0c3
fix slashing
pfefferle Jun 2, 2025
84fbff5
fix duplicate slashing
pfefferle Jun 2, 2025
2edca9d
Merge branch 'trunk' into change/storage-schema
pfefferle Jun 2, 2025
d5bea01
init
pfefferle Jun 2, 2025
1d355be
add fixes requested by @obenland
pfefferle Jun 2, 2025
d3f7f4d
add slashes also to title and excerpt
pfefferle Jun 2, 2025
afaf804
Merge branch 'change/storage-schema' into remove/follower-model
pfefferle Jun 3, 2025
1738968
simplify function names
pfefferle Jun 3, 2025
cfc6a73
slashify
pfefferle Jun 3, 2025
940d1bc
update function
pfefferle Jun 3, 2025
18f1b7e
fix init function
pfefferle Jun 3, 2025
54e899d
Merge branch 'trunk' into change/storage-schema
pfefferle Jun 3, 2025
9b7cefd
Merge branch 'change/storage-schema' into remove/follower-model
pfefferle Jun 3, 2025
e9025d1
update existing code
pfefferle Jun 3, 2025
564d5ea
Merge branch 'remove/follower-model' of https://github.com/Automattic…
pfefferle Jun 3, 2025
e054a20
improve code
pfefferle Jun 3, 2025
5797f40
Test fallback when meta_input is malformatted
pfefferle Jun 3, 2025
d023bcb
Merge branch 'change/storage-schema' into remove/follower-model
pfefferle Jun 3, 2025
652b11d
Merge branch 'trunk' into remove/follower-model
pfefferle Jun 4, 2025
5a675d6
revert changes
pfefferle Jun 4, 2025
e0f1f23
no need to use Actor object for internal cleanups
pfefferle Jun 4, 2025
d879735
simplify function names
pfefferle Jun 4, 2025
0abb3e1
use CPT for internal operations
pfefferle Jun 4, 2025
d66518a
more cleanups
pfefferle Jun 4, 2025
fe6bb0a
support upsert
pfefferle Jun 4, 2025
8c9320d
fix move
pfefferle Jun 4, 2025
34e7e46
Merge branch 'trunk' into remove/follower-model
pfefferle Jun 4, 2025
7c34160
fix move
pfefferle Jun 4, 2025
d24dffa
fix even more tests
pfefferle Jun 4, 2025
b87731f
fix error tests
pfefferle Jun 4, 2025
78343f9
fix follower tests
pfefferle Jun 4, 2025
cbe2979
fix scheduler
pfefferle Jun 4, 2025
5b27d27
fix phpcs
pfefferle Jun 4, 2025
220177f
fix another test
pfefferle Jun 4, 2025
d363dfb
remove unneeded checks
pfefferle Jun 4, 2025
0270b89
fix inbox test
pfefferle Jun 4, 2025
7c5d1e9
Add changelog
matticbot Jun 4, 2025
9dfdc1c
remove use of follower object
pfefferle Jun 4, 2025
7164e3c
Merge branch 'trunk' into remove/follower-model
pfefferle Jun 4, 2025
23b1f0b
not needed
pfefferle Jun 5, 2025
3e65f64
remove dependency to Follower model
pfefferle Jun 5, 2025
fae26a6
remove follower dependency
pfefferle Jun 5, 2025
ec4c455
fix migration tests
pfefferle Jun 5, 2025
9cfd4ba
Fix Move tests
pfefferle Jun 5, 2025
ad1fbbf
Remove one more dependency of the Follower Model
pfefferle Jun 5, 2025
b305b99
one more dependency
pfefferle Jun 5, 2025
e29f8c7
unify code
pfefferle Jun 5, 2025
ac9e706
Update includes/class-scheduler.php
pfefferle Jun 5, 2025
f5d81e9
Merge branch 'trunk' into remove/follower-model
pfefferle Jun 5, 2025
f92c0ff
Merge branch 'trunk' into remove/follower-model
pfefferle Jun 5, 2025
3c14f4d
Merge branch 'trunk' into remove/follower-model
pfefferle Jun 5, 2025
700bd87
Merge branch 'trunk' into remove/follower-model
pfefferle Jun 9, 2025
280e300
Merge branch 'trunk' into remove/follower-model
pfefferle Jun 9, 2025
6687e56
Merge branch 'trunk' into remove/follower-model
pfefferle Jun 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/changelog/1759-from-description
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: changed

Reworked follower structure to simplify handling and enable reuse for following mechanism.
1 change: 0 additions & 1 deletion includes/class-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
namespace Activitypub;

use Activitypub\Collection\Actors;
use Activitypub\Collection\Followers;

/**
* Block class.
Expand Down
2 changes: 0 additions & 2 deletions includes/class-migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,5 @@ public static function update_actor_json_storage( $batch_size = 100 ) {
'batch_size' => $batch_size,
);
}

return null;
}
}
43 changes: 22 additions & 21 deletions includes/class-scheduler.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ public static function unschedule_events_for_item( $outbox_item_id ) {
}

/**
* Update followers.
* Update imported actors.
*/
public static function update_followers() {
public static function update_imported_actors() {
$number = 5;

if ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ) {
Expand All @@ -156,19 +156,20 @@ public static function update_followers() {
*
* @param int $number The number of followers to update.
*/
$number = apply_filters( 'activitypub_update_followers_number', $number );
$followers = Followers::get_outdated_followers( $number );
$number = apply_filters( 'activitypub_update_followers_number', $number );
$actors = Actors::get_outdated( $number );

foreach ( $followers as $follower ) {
$meta = get_remote_metadata_by_actor( $follower->get_id(), false );
foreach ( $actors as $actor ) {
$meta = get_remote_metadata_by_actor( $actor->guid, false );

if ( empty( $meta ) || ! is_array( $meta ) || is_wp_error( $meta ) ) {
Followers::add_error( $follower->get__id(), $meta );
Actors::track_error( $actor->ID, 'Failed to fetch or parse metadata' );
} else {
$follower->from_array( $meta );
$follower->update();

$follower->clear_errors();
$id = Actors::add( $meta );
if ( \is_wp_error( $id ) ) {
continue;
}
Actors::clear_errors( $id );
}
}
}
Expand All @@ -188,27 +189,27 @@ public static function cleanup_followers() {
*
* @param int $number The number of followers to clean up.
*/
$number = apply_filters( 'activitypub_update_followers_number', $number );
$followers = Followers::get_faulty_followers( $number );
$number = apply_filters( 'activitypub_update_followers_number', $number );
$actors = Actors::get_faulty( $number );

foreach ( $followers as $follower ) {
$meta = get_remote_metadata_by_actor( $follower->get_url(), false );
foreach ( $actors as $actor ) {
$meta = get_remote_metadata_by_actor( $actor->guid, false );

if ( is_tombstone( $meta ) ) {
$follower->delete();
\wp_delete_post( $actor->ID );
} elseif ( empty( $meta ) || ! is_array( $meta ) || is_wp_error( $meta ) ) {
if ( $follower->count_errors() >= 5 ) {
$follower->delete();
if ( Actors::count_errors( $actor->ID ) >= 5 ) {
\wp_delete_post( $actor->ID );
\wp_schedule_single_event(
\time(),
'activitypub_delete_actor_interactions',
array( $follower->get_id() )
array( $actor->ID )
);
} else {
Followers::add_error( $follower->get__id(), $meta );
Actors::track_error( $actor->ID, $meta );
}
} else {
$follower->reset_errors();
Actors::clear_errors( $actor->ID );
}
}
}
Expand Down
Loading
Loading