fix(analytics): correct totalFollows query — use followerId not targetUsername#597
Open
hariom888 wants to merge 2 commits into
Open
fix(analytics): correct totalFollows query — use followerId not targetUsername#597hariom888 wants to merge 2 commits into
hariom888 wants to merge 2 commits into
Conversation
The totalFollows query in /api/analytics/overview was filtering by argetUsername: username (the authenticated user's own DevCard username), but follow.ts writes followLog rows with argetUsername = the external platform handle being followed and ollowerId = the actor's user ID.
This mismatch caused totalFollows to always be 0 for real users because no followLog row ever has targetUsername equal to a DevCard username — they hold external handles like GitHub usernames.
Fix: query by ollowerId: userId to correctly count outbound follow actions performed by the authenticated user, which is also what the existing code comment ('Follows performed BY this user') intended.
Also removes the now-unused username destructure from request.user.
|
@hariom888 is attempting to deploy a commit to the Prashantkumar Khatri's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Hi @hariom888, Thanks for opening this pull request. This PR has been automatically classified based on the files modified. Applied Labels
Primary Review Area
Reviewer@Harxhit has been identified as the primary reviewer for this pull request. If you have any questions regarding the affected area or implementation details, feel free to reach out to the assigned reviewer. Thank you for your contribution! |
CI — All Checks PassedBackend — PASS
Mobile — SKIP
Web — SKIP
Last updated: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #567
The
totalFollowsmetric inGET /api/analytics/overviewwas permanently zero for all real users due to a field/semantic mismatch between howfollow.tswritesfollowLogrows and howanalytics.tsreads them.Root cause
follow.tswritesfollowerIduserIdfollow.tswritestargetUsernameanalytics.tsreadtargetUsernameusernameBecause
targetUsernameinfollowLogalways holds an external handle (never a DevCard username), the analytics query matched zero rows in all realistic cases — producing atotalFollowsof0regardless of how many follows the user had actually performed.The code comment
// Follows performed BY this usercorrectly described the intent (outbound follow count), but the filtertargetUsername: usernameimplemented the opposite semantic (inbound follow count), and even that was broken because inbound DevCard-to-DevCard follows don't exist in the schema.Fix
Changed the
followLog.countfilter from:to:
Also removed the now-unused
usernamevariable from therequest.userdestructure.Tests added
Two new tests in
analytics.test.ts:followLog.countis called with{ followerId: MOCK_USER_ID, status: 'success' }and explicitly assertstargetUsernameis absent from the query — this would have caught the original bug.totalFollowsis0when no matching follow rows exist — baseline correctness check.Files changed
apps/backend/src/routes/analytics.ts— fix query; remove unusedusernameapps/backend/src/__tests__/analytics.test.ts— two regression testsTesting
All existing tests continue to pass; new tests demonstrate the fix.