Add optional refresh cooldown for non-admin users#7714
Open
seungoh-lee wants to merge 5 commits into
Open
Conversation
add notification
- Default non_admin_refresh_cooldown to 0 (opt-in) so the feature does not alter refresh behavior for existing non-admin users unless explicitly enabled. Matches the "Set to 0 to disable" hint in the settings UI and keeps the existing test_execute_new_query behavior intact. - Add TestNonAdminRefreshCooldown: disabled-by-default forces a fresh run, an enabled cooldown serves a recent cached result to non-admins, and admins bypass the cooldown entirely. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
1 issue found across 10 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
The refresh-cooldown countdown state lived at the top of QuerySource and QueryView, so during an active cooldown setInterval re-rendered the whole page (editor + visualizations) every second. Split useRefreshCooldown into a pure click-time gate (notifyRefreshCooldown / getRefreshCooldownRemaining) and the ticking display hook. The page now evaluates the cooldown gate at click time and the per-second countdown lives in a small RefreshCooldownLabel leaf, so only the button label re-renders while on cooldown. Execution gating (button, keyboard shortcut, parameter-change paths) is unchanged. DashboardHeader already scoped the hook to its RefreshButton leaf and is left untouched. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
3 issues found across 4 files (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="client/app/lib/hooks/useRefreshCooldown.js">
<violation number="1" location="client/app/lib/hooks/useRefreshCooldown.js:60">
P2: useEffect only depends on retrievedAt but reads mutable globals (currentUser.isAdmin, clientConfig.nonAdminRefreshCooldown), so UI cooldown state can become stale when those globals change at runtime without retrievedAt changing.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Author
|
@yoshiokatsuneo I would appreciate it if you could review the PR? Thanks |
Author
|
Friendly bump this PR has been open for a few weeks now and is still passing CI. Whenever a maintainer has a spare moment, I'd really appreciate a review. Happy to rebase or address any feedback. |
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.
What type of PR is this?
Description
Adds an optional refresh cooldown for non-admin users. When enabled (org setting
non_admin_refresh_cooldown, in seconds), non-admin users cannot re-run a query or refresh a dashboard more frequently than the configured interval. Admins are exempt.run_query): for non-admin users, when the cooldown is set, a forced refresh (max_age=0, or amax_agesmaller than the cooldown) is raised to the cooldown value, so a recent cached result is served instead of enqueuing a new execution.useRefreshCooldownhook drives the Query (QueryView/QuerySource) and Dashboard refresh buttons — they show aRefresh (Ns)countdown and surface a notification while on cooldown.clientConfig.nonAdminRefreshCooldown).Defaults to 0 (disabled), so refresh behavior is unchanged unless an admin opts in. Also configurable via the
REDASH_NON_ADMIN_REFRESH_COOLDOWNenvironment variable.How is this tested?
TestNonAdminRefreshCooldown(tests/handlers/test_query_results.py) covers: disabled-by-default forces a fresh run, an enabled cooldown serves a recent cached result to non-admins, and admins bypass the cooldown. Verified locally — backendtest_query_results.py: 38 passed; frontendpnpm run test(type-check + jest): 15 suites / 89 passed; ruff + black + eslint clean. Also exercised the button countdown / notification manually in a local Docker stack.Related Tickets & Documents
#7675
Mobile & Desktop Screenshots/Recordings (if there are UI changes)
UI changes: the Query/Dashboard refresh (and Execute) buttons show a
Refresh (Ns)countdown while on cooldown, plus a "Refresh is on cooldown" notification; a new numeric setting appears under Settings → General. Screenshots to be added.🤖 Generated with Claude Code