Skip to content

Conversation

@ruhanicpatel
Copy link

@ruhanicpatel ruhanicpatel commented Sep 11, 2025

  1. Issue

Link to the associated GitHub issue:
#298

Full path to the refactored file:
src/posts/topics.js

What do you think this file does?
This file has some helper functions to help get posts from a set, filter users that are blockec, etc. Generally, this file just helps to manage post data.

What is the scope of your refactoring within that file?
The scope of my refactoring was the getPostsFromSet function. My task was to decrease the number of parameters. How I did this was by working backwards. I had an opts object instead of all of the parameters. This way, you cna just extract whatever parameter you need without having them there in the parameter area of the function, which keeps the function very clean and manageable.

Which Qlty‑reported issue did you address?
Function with many parameters (count = 5): getPostsFromSet

  1. Refactoring
    How did the specific issue you chose impact the codebase’s adaptability?
    Since there were many parameters in the function initially, it made the code very hard to maintain. This is because, everutime a parameter was needed, all of the calls to the function had to be updated (since they were all parameters). This increased the chances of errors occuring and made it harder to make changes to the code in the future.

What changes did you make to resolve the issue?
I refactored the code to take in an opts object instead of all of the parameters. This makes for the parameters to be passed flexibly, but still holding similar structure to the initial function. I also added validation for the UID to make sure that no errors occur if it is not inputed/not correct.

How do your changes improve adaptability? Did you consider alternatives?
The changes improved adaptability by letting new parameters to be added without changing the function completely or breaking existing calls. It also makes the code easier to read and maintain. I didn't consider any alternative approaches.

  1. Validation
    How did you trigger the refactored code path from the UI?
    I triggered the refactored getPostsFromSet code from the UI whenever a user loaded a bunch of posts, like viewing a topic, scrolling through a feed, or navigating to a page with post listings. In this case, I viewed a bunch of replies to a post that I made.

Attach a screenshot of the logs and UI demonstrating the trigger.
Screenshot 2025-09-11 at 11 49 07 AM
logstatements

Attach a screenshot of qlty smells --no-snippets <full/path/to/file.js> showing fewer reported issues after the changes.
beofre refactor
after refactor

@coveralls
Copy link

Pull Request Test Coverage Report for Build 17651235381

Details

  • 1 of 7 (14.29%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.03%) to 78.504%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/posts/topics.js 1 7 14.29%
Totals Coverage Status
Change from base Build 17435863312: -0.03%
Covered Lines: 24692
Relevant Lines: 29612

💛 - Coveralls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants