Skip to content

Reduce network calls#2254

Merged
simo6529 merged 2 commits intomainfrom
reduce-network-calls
Apr 13, 2026
Merged

Reduce network calls#2254
simo6529 merged 2 commits intomainfrom
reduce-network-calls

Conversation

@simo6529
Copy link
Copy Markdown
Collaborator

@simo6529 simo6529 commented Apr 13, 2026

Summary by CodeRabbit

  • Bug Fixes

    • Improved leaderboard refresh behavior during vote reset operations by preventing data fetches while resets are in progress.
  • Refactor

    • Simplified leaderboard data fetching logic by replacing polling-based controls with explicit enable/disable state management.
    • Removed automatic polling mechanism that checked for new drops.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 13, 2026

📝 Walkthrough

Walkthrough

The PR refactors the leaderboard query control mechanism from a pausePolling flag to an enabled flag, removing tab-visibility polling machinery and the haveNewDrops return value. All dependent components and tests are updated to reflect this new control pattern.

Changes

Cohort / File(s) Summary
Hook Implementation
hooks/useWaveDropsLeaderboard.ts
Replaced pausePolling?: boolean prop with enabled?: boolean. Removed tab-visibility, capacitor, debounce, and polling timeout logic; removed haveNewDrops from return type. Query activation now determined by enabled && !!waveId.
Component Updates
components/brain/my-stream/votes/MyStreamWaveMyVotes.tsx, components/brain/my-stream/votes/MyStreamWaveMyVotesReset.tsx, components/home/next-mint-leading/NextMintLeadingSection.tsx
Updated hook integration from pausePolling to enabled control. Changed MyStreamWaveMyVotesReset callback prop from setPausePolling to onResettingChange. Modified reset component to toggle onResettingChange(true/false) around async reset operations.
Test Suite Updates
__tests__/components/brain/my-stream/votes/MyStreamWaveMyVotesReset.test.tsx, __tests__/hooks/useWaveDropsLeaderboard.test.ts, __tests__/hooks/useWaveDropsLeaderboard.extra.test.ts
Updated mock callbacks and assertions to match new onResettingChange prop and enabled control logic. Removed mocks for useDebounce and useCapacitor. Added helper utilities (getMainQueryOptions(), mockInfiniteQueryReturn()) to consolidate test setup and assertions.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • Trending to leaderboard #1739: Modifies useWaveDropsLeaderboard hook's polling and query control logic with parallel changes to hook props and fetching behavior.
  • My votes availability #1942: Updates MyStreamWaveMyVotes and MyStreamWaveMyVotesReset components with prop interface changes and reset workflow modifications.

Suggested reviewers

  • ragnep
  • prxt6529

Poem

🐰 Polling breaks its weary chain,
No more tabs or debounce pain,
enabled flags now take the lead,
Cleaner queries, lighter creed!
The leaderboard hops faster still—
Refactored with a developer's will. 🚀

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title "Reduce network calls" is directly related to the main objective of this changeset, which removes polling machinery, eliminates a secondary useQuery call, and consolidates query control mechanisms to minimize network requests.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch reduce-network-calls

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
components/brain/my-stream/votes/MyStreamWaveMyVotesReset.tsx (1)

67-85: ⚠️ Potential issue | 🟠 Major

Move the reset teardown into finally.

If any mutateAsync call rejects, Lines 82-85 are skipped. That leaves local isResetting stuck true and the parent stuck in onResettingChange(true), so the buttons stay disabled and leaderboard fetching never resumes.

💡 Suggested fix
   const selectedDropIds = Array.from(selected);

-  for (const dropId of selectedDropIds) {
-    await rateChangeMutation.mutateAsync({ dropId });
-    setResetProgress((prev) => prev + 1);
-  }
-
-  setIsResetting(false);
-  setResetProgress(0);
-  onResettingChange(false);
-  setTotalCount(0);
+  try {
+    for (const dropId of selectedDropIds) {
+      await rateChangeMutation.mutateAsync({ dropId });
+      setResetProgress((prev) => prev + 1);
+    }
+  } finally {
+    setIsResetting(false);
+    setResetProgress(0);
+    onResettingChange(false);
+    setTotalCount(0);
+  }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@components/brain/my-stream/votes/MyStreamWaveMyVotesReset.tsx` around lines
67 - 85, handleReset currently does the teardown (setIsResetting(false),
setResetProgress(0), onResettingChange(false), setTotalCount(0)) only after the
loop, so any rejection from rateChangeMutation.mutateAsync will skip those
lines; wrap the mutation loop in a try block and move all teardown calls into a
finally block to ensure they always run; keep the loop using
rateChangeMutation.mutateAsync({ dropId }) and the progress update
setResetProgress((prev)=>prev+1) inside try, and in finally call
setIsResetting(false), setResetProgress(0), onResettingChange(false) and
setTotalCount(0) so state/parent callbacks are always restored even on error.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@components/brain/my-stream/votes/MyStreamWaveMyVotes.tsx`:
- Around line 25-31: The intersection observer that triggers manual pagination
still calls fetchNextPage() while votes are resetting because TanStack Query's
enabled:false only stops automatic fetching; update the observer's guard to also
check isResettingVotes (use the isResettingVotes state) before calling
fetchNextPage() so that when isResettingVotes is true the observer will not call
fetchNextPage(); ensure you reference the fetchNextPage function and
isResettingVotes state in the observer condition (the same observer that
currently calls fetchNextPage()).

---

Outside diff comments:
In `@components/brain/my-stream/votes/MyStreamWaveMyVotesReset.tsx`:
- Around line 67-85: handleReset currently does the teardown
(setIsResetting(false), setResetProgress(0), onResettingChange(false),
setTotalCount(0)) only after the loop, so any rejection from
rateChangeMutation.mutateAsync will skip those lines; wrap the mutation loop in
a try block and move all teardown calls into a finally block to ensure they
always run; keep the loop using rateChangeMutation.mutateAsync({ dropId }) and
the progress update setResetProgress((prev)=>prev+1) inside try, and in finally
call setIsResetting(false), setResetProgress(0), onResettingChange(false) and
setTotalCount(0) so state/parent callbacks are always restored even on error.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 47c64915-498d-41fe-8316-ad67196af8e7

📥 Commits

Reviewing files that changed from the base of the PR and between 1794dcd and 7117649.

📒 Files selected for processing (7)
  • __tests__/components/brain/my-stream/votes/MyStreamWaveMyVotesReset.test.tsx
  • __tests__/hooks/useWaveDropsLeaderboard.extra.test.ts
  • __tests__/hooks/useWaveDropsLeaderboard.test.ts
  • components/brain/my-stream/votes/MyStreamWaveMyVotes.tsx
  • components/brain/my-stream/votes/MyStreamWaveMyVotesReset.tsx
  • components/home/next-mint-leading/NextMintLeadingSection.tsx
  • hooks/useWaveDropsLeaderboard.ts

Comment thread components/brain/my-stream/votes/MyStreamWaveMyVotes.tsx
@simo6529 simo6529 merged commit 4c5d895 into main Apr 13, 2026
8 checks passed
@simo6529 simo6529 deleted the reduce-network-calls branch April 13, 2026 06:16
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