Repository navigation
perf(oracle): throttle visibilitychange refetches in useOracle hooks (#519) - #626
Merged
nonsobethel0-dev merged 2 commits intoSep 23, 2026
Conversation
Both useOracleReading and useAllOracleReadings refetched on every visibilitychange, so rapid tab switching fired a request per switch. Track the last fetch time and only refetch on visibility if at least VISIBILITY_REFETCH_MIN_MS (half of ORACLE_REFRESH_INTERVAL_MS) has passed. Interval polling and manual refetch are unchanged. Closes Parashield-Protocol#519
Simulate 10 rapid tab switches and assert no extra fetch, then advance past VISIBILITY_REFETCH_MIN_MS and assert exactly one refetch, for both useOracleReading and useAllOracleReadings. Refs Parashield-Protocol#519
|
@oluwarantimini Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
❌ Deploy Preview for boisterous-sunshine-dd4c4c failed.
|
nonsobethel0-dev
merged commit Sep 23, 2026
f63f2cb
into
Parashield-Protocol:main
0 of 5 checks passed
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
src/hooks/useOracle.tsrefetched every time the tab became visible. Switching tabs quickly (10 times in 5 seconds, for example) sent one oracle API request per switch, even though the hook already polls everyORACLE_REFRESH_INTERVAL_MS(60s).Both hooks had this problem:
useOracleReadinganduseAllOracleReadings, which backs the oracle page.Fix
This follows the approach suggested in the issue:
VISIBILITY_REFETCH_MIN_MS = ORACLE_REFRESH_INTERVAL_MS / 2(30s by default). It is exported so tests can use it.lastFetchAtRef). The ref is updated at the start of everyload(), whether the fetch came from the first load, the polling interval, a visibility change or a manualrefetch.visibilitychangehandler now refetches only if the tab is visible and the last fetch was at leastVISIBILITY_REFETCH_MIN_MSago.Unchanged:
refetch()is not throttled, so a user who clicks refresh always gets fresh data.Tests
The new tests are in
src/hooks/__tests__/useOracle.test.ts. They stubDate.nowand dispatch realvisibilitychangeevents:useOracleReading: 10 rapid visibility changes trigger no extra fetch. After moving the clock pastVISIBILITY_REFETCH_MIN_MS, one more change triggers exactly one refetch.useAllOracleReadings: the same check.Results:
useOracle.ts, both new tests fail (2 failed, 7 passed), so they do catch the bug.tsc --noEmitreports no errors in the changed files. The errors it does report are in unrelated files and were already there.Closes [perf] Oracle readings refetch on every visibility change without debounce #519
Closes [ux] Category filter state lost on page navigation #518
Closes [bug] Race condition in useOracleReading when key changes rapidly #516
Closes [bug]科学计数法输入可以绕过覆盖范围验证 #517