Skip to content

Conversation

@SpicySam
Copy link

@SpicySam SpicySam commented Sep 5, 2025

The file being worked on handles topic posts, including all the a user puts inside a new topic.
The scope of this refactoring covers the Topics.addPostData function, which takes one or more posts adds all the extra information needed to display them the forum or via API.
The specific issue with Topics.addPostData was high function complexity.
This issue impacted the codebase's adaptability by making it harder to extend and modify by requiring it add more to the same long function, increasing the risk of bugs there and elsewhere. It also meant we couldn't test specific parts in isolation, like only bookmarks or user info.
To address this issue, I changed the Topics.addPostData function to simplify it by adding helper functions that each take in fewer arguments. The context constant means fewer arguments are passing from the getPostEnhancements helper function into the changePost helper function. These functions are split off from addPostData to increase understandability and decrease function complexity. These changes have been tested and verified with qlty smells, npm lint, and npm test.
These changes create specific helper functions for specific responsibilities, meaning if someone wants to change one part, they can do that in isolation and test it in isolation. It improves readability because of fewer arguments into functions and specialized functions.
I triggered the code path by creating a new topic with data.

Screenshot 2025-09-04 230931 Screenshot 2025-09-04 230811 Screenshot 2025-09-04 223549

@coveralls
Copy link

coveralls commented Sep 5, 2025

Pull Request Test Coverage Report for Build 17743609751

Details

  • 34 of 41 (82.93%) changed or added relevant lines in 1 file are covered.
  • 5 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.02%) to 78.506%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/topics/posts.js 34 41 82.93%
Files with Coverage Reduction New Missed Lines %
src/controllers/topics.js 5 80.95%
Totals Coverage Status
Change from base Build 17435863312: -0.02%
Covered Lines: 24704
Relevant Lines: 29626

💛 - 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