Skip to content

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

Open
wants to merge 4 commits into
base: trunk
Choose a base branch
from

Conversation

obenland
Copy link
Member

Fixes #

Proposed changes:

This PR improves the Following class with better documentation and more efficient method implementations:

  • Remove unused import: Removed unused Activitypub\Http import
  • Fix @see references: Updated @see tags to use proper namespace format (\Activitypub\follow instead of Activitypub\follow)
  • Improve return type documentation: Updated follow() method documentation to accurately reflect all possible return types
  • Optimize count methods: Modified count methods (count_following, count_pending, count_all) to use minimal parameters (limit=1) instead of fetching all data when only the total count is needed
  • Fix documentation typo: Corrected return type documentation in get_all_with_count() to reference 'following' instead of 'followers'

Other information:

  • Have you written new tests for your changes, if applicable? - No new functionality, only optimizations and documentation improvements

Testing instructions:

  • Go to WordPress admin and navigate to ActivityPub settings
  • Test following/unfollowing functionality to ensure it still works correctly
  • Verify that follower counts are displayed correctly in the UI
  • Check that performance is maintained or improved when viewing large follower lists

Changelog entry

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

Significance

  • Patch

Type

  • Changed - for changes in existing functionality

Message

Improve Following class documentation and optimize count methods for better performance

- Remove unused Http import
- Fix @see references to use proper namespace format (\Activitypub\follow)
- Update return type documentation for follow() method to be more accurate
- Optimize count methods to avoid unnecessary data retrieval by using minimal number parameter
- Fix return type documentation for get_all_with_count to correctly reference 'following' instead of 'followers'
@Copilot Copilot AI review requested due to automatic review settings August 21, 2025 13:56
@obenland obenland self-assigned this Aug 21, 2025
@obenland obenland requested a review from pfefferle August 21, 2025 13:56
Copy link

@Copilot 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

This PR enhances the Following class by improving documentation quality and optimizing performance of count methods. The changes focus on cleaning up imports, fixing documentation references, and making count operations more efficient by fetching minimal data when only totals are needed.

  • Remove unused Activitypub\Http import and fix namespace references in documentation
  • Optimize count methods to use limit=1 instead of fetching all data when only counting
  • Improve method documentation with accurate return types and fix typos

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

* Data about the followings.
*
* @type \WP_Post[] $followers List of `Follower` objects.
* @type int $total Total number of followers.
Copy link
Preview

Copilot AI Aug 21, 2025

Choose a reason for hiding this comment

The 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
* @type int $total Total number of followers.
* @type \WP_Post[] $following List of `Following` objects.
* @type int $total Total number of followings.

Copilot uses AI. Check for mistakes.

* Data about the followings.
*
* @type \WP_Post[] $followers List of `Follower` objects.
* @type int $total Total number of followers.
Copy link
Preview

Copilot AI Aug 21, 2025

Choose a reason for hiding this comment

The 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
* @type int $total Total number of followers.
* @type \WP_Post[] $following List of `Following` objects.
* @type int $total Total number of following.

Copilot uses AI. Check for mistakes.

*
* @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.
Copy link
Member Author

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?

Adjusted the PHPDoc return types for the follow and unfollow functions to more accurately reflect their possible return values. This improves code documentation and helps with static analysis.
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.

2 participants