-
Notifications
You must be signed in to change notification settings - Fork 85
Refactor collection classes to use unified query methods #2340
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
Conversation
Replaces legacy methods in Blocked_Actors, Followers, Following, and Interactions classes with new unified methods such as query(), get_many(), add(), remove(), and count(). Deprecated old methods and updated all usages throughout the codebase, including handlers, REST controllers, admin tables, integration, CLI, and tests, to use the new APIs. This improves consistency, maintainability, and clarity in collection handling.
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.
Pull Request Overview
This PR refactors collection classes (Blocked_Actors, Followers, Following, and Interactions) to use unified, more consistent method names. The legacy methods are deprecated and replaced with clearer alternatives like query()
, get_many()
, add()
, remove()
, and count()
. All usages throughout the codebase have been updated to use the new APIs.
Key changes:
- Method renaming for consistency:
add_follower()
→add()
,get_followers()
→get_many()
,count_followers()
→count()
, etc. - Deprecated old methods are maintained with
_deprecated_function()
calls - All callsites updated across handlers, REST controllers, admin tables, CLI, tests, and integrations
Reviewed Changes
Copilot reviewed 31 out of 31 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
includes/collection/class-followers.php | Refactored to use add() , get_many() , get_by_uri() , query() , count() methods; deprecated old methods |
includes/collection/class-following.php | Refactored to use query() , get_many() , count() methods; deprecated old methods |
includes/collection/class-interactions.php | Refactored to use get_by_id() , get_by_actor() methods; deprecated old methods |
includes/collection/class-blocked-actors.php | Refactored to use add() , remove() , query() , get_many() methods; deprecated old methods |
includes/handler/class-follow.php | Updated to use Followers::add() |
includes/handler/class-delete.php | Updated to use Interactions::get_by_actor() and get_by_id() |
includes/rest/class-followers-controller.php | Updated to use Followers::query() |
includes/rest/class-following-controller.php | Updated to use Following::query() |
includes/wp-admin/table/class-followers.php | Updated to use Follower_Collection::query() and count() |
includes/wp-admin/table/class-following.php | Updated to use Following_Collection::query() with inline meta_query setup |
includes/wp-admin/table/class-blocked-actors.php | Updated to use Blocked_Actors_Collection::query() |
includes/class-moderation.php | Updated to use Blocked_Actors::add() , remove() , get_many() |
includes/class-migration.php | Updated to use Followers::add() and get_many() |
includes/functions.php | Updated to use Followers::get_many() and count() |
local/class-cli.php | Updated to use Followers::add() |
integration/class-enable-mastodon-apps.php | Updated to use Followers::get_many() and count() |
src/followers/render.php | Updated to use Followers::query() |
src/follow-me/render.php | Updated to use Followers::count() |
build/followers/render.php | Updated to use Followers::query() |
build/follow-me/render.php | Updated to use Followers::count() |
tests/phpunit/tests/* | Updated all test files to use new method names |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
I let claude analyze the current collections to remove redundant function naming and to unify them over all classes. It came up with Curious about your feedback @obenland |
Co-authored-by: Copilot <[email protected]>
I think it’s a good idea to unify all interaction activities under the same logic. I’m not entirely sure how interactions actually work in the Fediverse implementation of Lemmy, but it seems that when you press Dislike after Like, the previous Like is automatically undone. https://join-lemmy.org/docs/contributors/05-federation.html#undo-like-or-dislike-post-or-comment |
@Jiwoon-Kim this PR has nothing to do with Activities! Collections are meant to help with DB queries. |
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.
I love it!
For all the _deprecated_function()
calls that are added, let's backslashit()
and add a blank line after them? That way the return
statements also have a blank line ahead of them. (It felt weird to add each instance as a suggestion and give you a wall of suggestions)
Co-authored-by: Konstantin Obenland <[email protected]>
Co-authored-by: Konstantin Obenland <[email protected]>
Co-authored-by: Konstantin Obenland <[email protected]>
Moved meta_query logic for pending and all followings into dedicated methods in Following_Collection, improving code reuse and clarity. Updated admin table to use these methods instead of duplicating query logic.
Renamed and refactored methods in Following_Collection to use query_pending and query_all for pending and all followings, improving code clarity and reducing duplication. Updated usages in admin table to match new method names.
Introduces get_pending_with_count() and get_all_with_count() methods to retrieve pending and all followings with total count for pagination. These methods are marked as deprecated in favor of query_pending() and query_all().
Replaces calls to Following::count and Following_Collection::count with count_by_status in Heartbeat and Following classes for more accurate status-based counting.
Replaces legacy methods in Blocked_Actors, Followers, Following, and Interactions classes with new unified methods such as query(), get_many(), add(), remove(), and count(). Deprecated old methods and updated all usages throughout the codebase, including handlers, REST controllers, admin tables, integration, CLI, and tests, to use the new APIs. This improves consistency, maintainability, and clarity in collection handling.
Proposed changes:
add_follower()
→add()
,get_followers()
→get_many()
,count_followers()
→count()
, etc._deprecated_function()
callsOther information:
Testing instructions:
Changelog entry
Changelog Entry Details
Significance
Type
Message