fix: change create a poll LIP fetch to cached runtime API call#712
fix: change create a poll LIP fetch to cached runtime API call#712ECWireless wants to merge 3 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughAdds a Poll LIPs Runtime Fetching
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@lib/api/poll-lips.ts`:
- Around line 82-110: The request-time flow in pollLips currently performs
GitHub, subgraph, and per-poll IPFS calls without any timeout or concurrency
control, so bound those upstream fetches and fail fast through the existing
error handling path. Update the polling logic around githubFetch,
createApolloFetch, and the Promise.all over pollsData.polls to use server-side
request timeouts and a capped IPFS concurrency strategy instead of unbounded
parallel requests. Keep the existing validation and error-throwing behavior, but
ensure slow or excessive upstream calls cannot hold the route until platform
timeout.
- Around line 140-142: The sorting in lips.sort inside poll-lips.ts is comparing
lip ids as strings, which causes lexicographic ordering instead of numeric
ordering. Update the comparator in the lips sorting logic to convert the
attributes.lip values to numbers before comparing so higher-numbered LIPs appear
first correctly in the Create Poll list. Keep the change localized to the
sorting expression used by the lips array and ensure it still handles missing
attributes safely.
In `@pages/api/polls/lips.ts`:
- Around line 17-23: The Cache-Control header is being applied before
getPollLips() succeeds, so externalApiError() can return a cacheable transient
failure. Move the getCacheControlHeader("revalidate") header assignment to after
getPollLips() succeeds in the lips API handler, or explicitly set no-store in
the catch path so failures from externalApiError are never cached. Use the
getPollLips and externalApiError flow in the lips route to place the fix
correctly.
In `@pages/voting/create-poll.tsx`:
- Around line 71-73: Keep the selected proposal anchored to a stable LIP
identifier instead of list indexes or gitCommitHash. Update the proposal
rendering in create-poll.tsx so the radio value/key and lookup use
lip.attributes.lip, and adjust the selectedProposal state to store that stable
id. In the create-poll selection flow and the related proposal list/radio
handlers, clear or remap the selection whenever the chosen LIP is no longer
present after SWR refresh or filtering.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 90cb7289-dbca-448c-83ba-701c9c8cbb7b
📒 Files selected for processing (4)
lib/api/poll-lips.tslib/api/types/get-poll-lips.tspages/api/polls/lips.tspages/voting/create-poll.tsx
There was a problem hiding this comment.
Pull request overview
This PR moves “eligible LIPs” loading for /voting/create-poll from build-time ISR to a runtime API route with short CDN stale-while-revalidate caching, so newly proposed LIPs appear after a reload without waiting for a redeploy.
Changes:
- Added
GET /api/polls/lipsthat assembles eligible LIPs at request time with cache headers. - Refactored
/voting/create-pollto fetch LIPs via SWR and display loading/error states. - Extracted LIP/poll filtering logic into
lib/api/poll-lips.tswith shared response types.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| pages/voting/create-poll.tsx | Switches LIP loading to SWR and adds loading/error UI; updates selection/link logic. |
| pages/api/polls/lips.ts | New API route serving eligible LIPs with cache headers. |
| lib/api/types/get-poll-lips.ts | Adds shared types for the LIPs API payload. |
| lib/api/poll-lips.ts | Implements runtime aggregation/filtering of eligible LIPs from GitHub + subgraph/IPFS. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Description
This updates Create Poll so eligible LIPs are loaded at runtime through a short-cached API route instead of being baked into the page with ISR. That makes new proposed LIPs appear after reload almost immediately, while preserving the existing filtering for LIPs that are proposed, not part of another LIP, and do not already have a poll.
Type of Change
Related Issue(s)
Closes: #562
Changes Made
GET /api/polls/lipswith short CDN stale-while-revalidate caching./voting/create-pollto fetch LIPs via SWR and show loading/error states.Testing
How to test
Impact / Risk
Risk level: Low
Impacted areas: UI / API
User impact: Those trying to put their LIP on-chain through
/voting/create-pollno longer have to wait until the site is redeployed to see their GitHub version of the proposal.Rollback plan: Vercel rollback, then manual git revert.
Summary by CodeRabbit
New Features
Bug Fixes