Skip to content

Conversation

@dsblack0
Copy link

@dsblack0 dsblack0 commented Sep 5, 2025

P1B: Starter Task: Refactoring PR

You are not permitted to use generative AI services (e.g., ChatGPT) to compose the answers.
Any such use will be treated as a violation of academic integrity.

1. Issue

Please provide a link to the associated GitHub issue:

Link to the associated GitHub issue:
#154

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

What do you think this file does?
I think this file is responsible for getting information about the unread topics, including the number of unread topics, and the IDs and data for each unread topic. Whenever the site is reloaded, parts of this file get run to recalculate how many unread topics there are, in order to display the accurate number on the navigation button to access unread topics.

What is the scope of your refactoring within that file?
The function I worked on was getTids. To reduce the function's complexity, I split the main parts of the function into various helper functions that can be called in getTids.

Which Qlty‑reported issue did you address?

 92  Function with high complexity (count = 20): getTids

2. Refactoring

How did the specific issue you chose impact the codebase’s adaptability?
The getTids function is very long and complex, so it can be difficult to understand what exact steps are being taken to compile all of the topics' details that are returned by the function. This can make it harder for anyone trying to add to or modify functionalities related to unread topics. Additionally, if there was an error somewhere in the function, it would be difficult to identify the exact origin of the error within the large amount of code that makes up this single function.

What changes did you make to resolve the issue?
As the getTids function was taking multiple different steps to compile the information on the unread topics, I split up the large function into smaller helper functions that deal with each of the main steps. I called these shorter helper functions in getTids to make this main function shorter and clearer.

How do your changes improve adaptability? Did you consider alternatives?
My changes help to make the getTids function shorter and easier to understand, as each of the helper functions is named based on the specific functionality that it is accomplishing, so it is clearer what specific parts of the code are accomplishing. Having multiple helper functions makes the code more readable and also makes it easier to test specific steps in the process of collecting the unread topics' data. I didn't consider any alternatives, as with the function being very long, splitting it into smaller functions seems to be the most effective method to improve adaptability.

3. Validation

How did you trigger the refactored code path from the UI?
There were two ways I was able to trigger the refactored code path from the UI. The main method was to reload any page on the site, as getTids would be run in order to recalculate the number of unread topics, which is displayed in the sidebar (as shown in the first screenshot below). The second method was to click on the navigation button in the sidebar to open the page with unread topics (as shown in the second and third screenshots below).

Attach a screenshot of the logs and UI demonstrating the trigger.
P1B-logs

Method 1: Reload
image

Method 2: Navigate to the unread topics page
P1B-UI-1
P1B-UI-2

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

@coveralls
Copy link

Pull Request Test Coverage Report for Build 17483038758

Details

  • 37 of 38 (97.37%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.006%) to 78.535%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/topics/unread.js 37 38 97.37%
Totals Coverage Status
Change from base Build 17435863312: 0.006%
Covered Lines: 24704
Relevant Lines: 29618

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