Skip to content

Conversation

@JRNukala
Copy link

@JRNukala JRNukala commented Jan 23, 2026

P1B: Starter Task: Refactoring PR

1. Issue

#123 (comment)

Full path to the refactored file:
src/socket.io/admin/rooms.js

What do you think this file does?
I think what this file does is that it fetches the amount of online users and other metrics for the admin dashboard to then fetch and represent in graphs and numbers.

What is the scope of your refactoring within that file?
I refactored the "SocketRooms.getLocalStats" functions where I took some high complextiry parts of the code and changed into some helper functions which make it easier to read. I created two new fuhelper functions (processRoomData and createEmptyStatsObject) in order to do so. They span from line 90 to line 147

Which Qlty‑reported issue did you address?
Function with high complexity (Count = 10)

2. Refactoring

How did the specific issue you chose impact the codebase’s maintainability?
The function I chose was cluttery and had a lot of nester ifs and for loops which don't make sense to someone who looks at it randomly.

What changes did you make to resolve the issue?
When someone looks at the code, it looks much less cluttery with the new helper functions. I also added some comments to make it more readable and maintainable.

How do your changes improve maintainability? Did you consider alternatives?
They clearly break down the functionality of the function into more clear helper functions, all of which have good names and easily understandable code. The comments also increase readability.

3. Validation

How did you trigger the refactored code path from the UI?
I wasn't able to trigger the function directly from the UI or through doing actions. I tinkered around the website through multiple instances of NodeBB at the same time (since it is a admin feature that has analytics). However none of them triggered anything. I tried to ask an LLM where this code could possibly be triggered and its ideas were also not working. So for now I am showing when it gets triggered in the npm run test (which means its running my code).
Attach a screenshot of the logs and UI demonstrating the trigger.
Screenshot 2026-01-23 at 6 20 52 PM
Attach a screenshot of qlty smells --no-snippets src/socket.io/admin/rooms.js showing fewer reported issues after the changes.
Before
Screenshot 2026-01-22 at 7 14 42 PM
After
Screenshot 2026-01-23 at 6 21 30 PM

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.

1 participant