-
Notifications
You must be signed in to change notification settings - Fork 81
Improve Following class documentation and method efficiency #2086
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
base: trunk
Are you sure you want to change the base?
Changes from all commits
ee68cfa
bf631f7
e555956
f8a3075
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: patch | ||
Type: changed | ||
|
||
Improve Following class documentation and optimize count methods for better performance |
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -8,7 +8,6 @@ | |||||||||||||
namespace Activitypub\Collection; | ||||||||||||||
|
||||||||||||||
use Activitypub\Activity\Activity; | ||||||||||||||
use Activitypub\Http; | ||||||||||||||
|
||||||||||||||
use function Activitypub\add_to_outbox; | ||||||||||||||
|
||||||||||||||
|
@@ -54,14 +53,14 @@ class Following { | |||||||||||||
/** | ||||||||||||||
* Follow a user. | ||||||||||||||
* | ||||||||||||||
* Please do not use this method directly, use `Activitypub\follow` instead. | ||||||||||||||
* Please do not use this method directly, use `\Activitypub\follow` instead. | ||||||||||||||
* | ||||||||||||||
* @see Activitypub\follow | ||||||||||||||
* @see \Activitypub\follow | ||||||||||||||
* | ||||||||||||||
* @param \WP_Post|int $post The ID of the remote Actor. | ||||||||||||||
* @param int $user_id The ID of the WordPress User. | ||||||||||||||
* | ||||||||||||||
* @return \WP_Post|\WP_Error The ID of the Actor or a WP_Error. | ||||||||||||||
* @return int|false|\WP_Post|\WP_Error The Outbox ID or false on failure, the Actor post or a WP_Error. | ||||||||||||||
*/ | ||||||||||||||
public static function follow( $post, $user_id ) { | ||||||||||||||
$post = \get_post( $post ); | ||||||||||||||
|
@@ -146,9 +145,9 @@ public static function reject( $post, $user_id ) { | |||||||||||||
/** | ||||||||||||||
* Remove a follow request. | ||||||||||||||
* | ||||||||||||||
* Please do not use this method directly, use `Activitypub\unfollow` instead. | ||||||||||||||
* Please do not use this method directly, use `\Activitypub\unfollow` instead. | ||||||||||||||
* | ||||||||||||||
* @see Activitypub\unfollow | ||||||||||||||
* @see \Activitypub\unfollow | ||||||||||||||
* | ||||||||||||||
* @param \WP_Post|int $post The ID of the remote Actor. | ||||||||||||||
* @param int $user_id The ID of the WordPress User. | ||||||||||||||
|
@@ -264,7 +263,7 @@ public static function get_following( $user_id, $number = -1, $page = null, $arg | |||||||||||||
* @return int The total number of followings. | ||||||||||||||
*/ | ||||||||||||||
public static function count_following( $user_id ) { | ||||||||||||||
return self::get_following_with_count( $user_id, -1, null, array() )['total']; | ||||||||||||||
return self::get_following_with_count( $user_id, 1 )['total']; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
|
@@ -330,7 +329,7 @@ public static function get_pending( $user_id, $number = -1, $page = null, $args | |||||||||||||
* @return int The total number of pending followings. | ||||||||||||||
*/ | ||||||||||||||
public static function count_pending( $user_id ) { | ||||||||||||||
return self::get_pending_with_count( $user_id, -1, null, array() )['total']; | ||||||||||||||
return self::get_pending_with_count( $user_id, 1 )['total']; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
|
@@ -341,7 +340,12 @@ public static function count_pending( $user_id ) { | |||||||||||||
* @param int $page Page number. | ||||||||||||||
* @param array $args The WP_Query arguments. | ||||||||||||||
* | ||||||||||||||
* @return \WP_Post[] List of `Following` objects. | ||||||||||||||
* @return array { | ||||||||||||||
* Data about the followings. | ||||||||||||||
* | ||||||||||||||
* @type \WP_Post[] $followers List of `Follower` objects. | ||||||||||||||
* @type int $total Total number of followers. | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The documentation incorrectly refers to 'followers' and 'Follower' objects in a Following class. This should be 'following' and 'Following' objects to match the class context.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The documentation incorrectly refers to 'followers' when it should be 'following' to match the class context.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||
* } | ||||||||||||||
*/ | ||||||||||||||
public static function get_all_with_count( $user_id, $number = -1, $page = null, $args = array() ) { | ||||||||||||||
$defaults = array( | ||||||||||||||
|
@@ -380,7 +384,7 @@ public static function get_all_with_count( $user_id, $number = -1, $page = null, | |||||||||||||
* @return \WP_Post[] List of `Following` objects. | ||||||||||||||
*/ | ||||||||||||||
public static function get_all( $user_id ) { | ||||||||||||||
return self::get_all_with_count( $user_id, -1, null, array() )['following']; | ||||||||||||||
return self::get_all_with_count( $user_id )['following']; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
|
@@ -391,7 +395,7 @@ public static function get_all( $user_id ) { | |||||||||||||
* @return int The total number of all followings. | ||||||||||||||
*/ | ||||||||||||||
public static function count_all( $user_id ) { | ||||||||||||||
return self::get_all_with_count( $user_id, -1, null, array() )['total']; | ||||||||||||||
return self::get_all_with_count( $user_id, 1 )['total']; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
|
@@ -403,9 +407,9 @@ public static function count_all( $user_id ) { | |||||||||||||
*/ | ||||||||||||||
public static function count( $user_id ) { | ||||||||||||||
return array( | ||||||||||||||
self::ALL => self::get_all_with_count( $user_id, -1, null, array() )['total'], | ||||||||||||||
self::ACCEPTED => self::get_following_with_count( $user_id, -1, null, array() )['total'], | ||||||||||||||
self::PENDING => self::get_pending_with_count( $user_id, -1, null, array() )['total'], | ||||||||||||||
self::ALL => self::get_all_with_count( $user_id, 1 )['total'], | ||||||||||||||
self::ACCEPTED => self::get_following_with_count( $user_id, 1 )['total'], | ||||||||||||||
self::PENDING => self::get_pending_with_count( $user_id, 1 )['total'], | ||||||||||||||
); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pfefferle The possible return values of this method are a bit confusing. It's a WP_Error with an invalid actor, the outbox item ID on success and false on failure, and if we didn't get to adding it to the outbox, the actor post. Would it be possible to limit it to two types?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we do this as part of this PR or in a follow up?
can you file an issue if it should be a follow up?