fix(watch-button): eliminate N+1 API calls on profile watchlist#60
Open
Alm0stSurely wants to merge 1 commit intoiiitl:mainfrom
Open
fix(watch-button): eliminate N+1 API calls on profile watchlist#60Alm0stSurely wants to merge 1 commit intoiiitl:mainfrom
Alm0stSurely wants to merge 1 commit intoiiitl:mainfrom
Conversation
## Problem
The WatchButton component was firing N separate checkIsWatched() API
calls for N repos in the watchlist, even though the parent already knew
these repos were watched by definition.
## Solution
- Add optional initialIsWatched prop to skip redundant API calls
- Add optional onUnwatch callback for optimistic UI removal
- Profile page now passes initialIsWatched={true} for all watchlist items
## Result
Profile page with 10 watched repos now fires 1 API call instead of 11.
Fixes iiitl#57
6 tasks
Collaborator
|
Great work @Alm0stSurely ! Could you please update the PR description to match our Official Contribution Template? Following the format makes it much easier for us to review your logic and track the related issue. 📖 Reference: Contributing Guide - PR Format Once you've updated the description, let me know and I'll take another look!" |
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.
Problem
On the Profile page, each in the Watchlist section independently called
checkIsWatched()on mount. For a user with N watched repos, this resulted in N+1 API requests (1 forgetWatchlist()+ N for individual checks), even though the parent already knew by definition that every repo in the watchlist was being watched.Analysis
The N+1 pattern occurred because:
WatchButtonhad no way to receive initial state from its parentuseEffectfetch on mountSolution
Added optional
initialIsWatched?: booleanprop toWatchButtoncheckIsWatchedAPI callinitialIsWatched === undefinedto distinguish "unknown" from "known false"Added optional
onUnwatch?: () => voidcallbackUpdated Profile page to pass
initialIsWatched={true}for all watchlist itemsVerification
npx tsc --noEmit)Files Changed
frontend/components/watch-button.tsx— add props, conditional fetch skipfrontend/app/(auth)/profile/page.tsx— pass initial state and unwatch handlerFixes #57