Skip to content
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

US10: Add "Most Followers" tab to display all users ranked by their followers #37

Merged
merged 12 commits into from
Oct 8, 2024

Conversation

paulinezhanghh
Copy link

@paulinezhanghh paulinezhanghh commented Oct 6, 2024

Overview

This pull request implements User Story 10: “As a user, I want to see the most popular users across all users on the ‘Users’ page, so that I can have a better idea of who has the most followers on NodeBB.” We have added a new tab called "Most Followers" on the Users page, displaying users sorted by their follower count in descending order.

Features Implemented

1. Frontend Changes

  • Added “Most Followers” Tab: Created a new tab on the Users page labeled "Most Followers", enabling users to view the most popular users based on follower count.
  • Modified User Card Display: Adjusted the logic to dynamically render user cards using the new sorting attribute, showing users in descending order according to their number of followers.

2. Backend Changes

  • Schema Updates: we updated the schema in the YAML files to include a new attribute followerCount for each user. This attribute is used to store the total number of followers a user has, which allows efficient retrieval and sorting when fetching user data.

  • Controller Modifications
    (1) Sorting Logic: Modified the controller logic to sort users based on the followerCount attribute. This ensures that users are correctly ordered by the number of followers they have when the "Most Followers" tab is accessed.
    (2) New Endpoint: Introduced a new API endpoint (/api/users?section=sort-followers) specifically for retrieving users sorted by their follower count.
    (3) Database Query Adjustments: Updated database queries to retrieve and sort users based on the new followerCount field, ensuring that the sorting remains efficient even with a large number of users.

  • Follower Count Management
    (1) Increment/Decrement Operations: Adjusted the code to update the followerCount value whenever a user follows or unfollows another user. The logic now correctly increments or decrements the count, and the value is stored back in the database for consistency.
    (2) Bulk Update Function: Implemented a function (updateFollowerCount) that efficiently updates the follower count for multiple users at once. This is particularly useful for scenarios where multiple follow/unfollow events occur in a short period.

Test Coverage

  • Comprehensive Tests: We wrote tests to validate the sorting behavior based on follower counts. This includes checking the order when users follow/unfollow each other, ensuring that the data returned by the API matches the expected order.
  • Edge Cases: Tests were also added to cover edge cases, such as when a user has no followers or when all users have the same number of followers, to verify that the sorting logic handles these scenarios correctly.

Solves: #27 #28 #29 #35 #36

Screenshot

Screenshot 2024-10-05 at 23 12 01

These 2 tpl files were initially ignored. However, we need to track them for front-end changes.
We want to display the number of followers users have under the tab of most followers.
We have the number showing correctly now, but we need to sort it in the correct order. So, we dived deep into the logic of the top poster and tried to copy the logic of it to the most popular in the file followe.js.
@LeeMEow23 LeeMEow23 self-requested a review October 6, 2024 02:52
@LeeMEow23 LeeMEow23 added the enhancement New feature or request label Oct 6, 2024
@LeeMEow23 LeeMEow23 added this to the Sprint 2 milestone Oct 6, 2024
@LeeMEow23 LeeMEow23 requested review from ethantanjw and e5z26 and removed request for ethantanjw October 6, 2024 02:53
@coveralls
Copy link

coveralls commented Oct 6, 2024

Pull Request Test Coverage Report for Build 11239532554

Details

  • 24 of 24 (100.0%) changed or added relevant lines in 2 files are covered.
  • 2 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.03%) to 82.722%

Files with Coverage Reduction New Missed Lines %
src/controllers/users.js 1 63.25%
src/user/follow.js 1 82.05%
Totals Coverage Status
Change from base Build 11186363416: 0.03%
Covered Lines: 22358
Relevant Lines: 25612

💛 - Coveralls

Copy link

@LeeMEow23 LeeMEow23 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The newly added code looks pretty clean and organized to me! The test cases for this us10 also covers edges cases I can think of, thanks Justin and Ethan!

@LeeMEow23 LeeMEow23 changed the title Us 10 Restart: Fixing the sorting issues US10: Add "Most Followers" Tab to display all users ranked by their followers Oct 8, 2024
@LeeMEow23 LeeMEow23 changed the title US10: Add "Most Followers" Tab to display all users ranked by their followers US10: Add "Most Followers" tab to display all users ranked by their followers Oct 8, 2024
Copy link

@e5z26 e5z26 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code respects existing structure, new features in code blend well with current design, tests work good and cover different scenarios

@LeeMEow23 LeeMEow23 merged commit d24ff85 into f24 Oct 8, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants