feat: use faster refresh interval when jobs are processing#94
Open
tifa2UP wants to merge 1 commit intofeat/documents-processing-calloutfrom
Open
feat: use faster refresh interval when jobs are processing#94tifa2UP wants to merge 1 commit intofeat/documents-processing-calloutfrom
tifa2UP wants to merge 1 commit intofeat/documents-processing-calloutfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Comment on lines
+44
to
+47
| refetchInterval: (query) => { | ||
| const hasPending = (query.state.data?.records.length ?? 0) > 0; | ||
| return hasPending ? 1_500 : 15_000; | ||
| }, |
Contributor
There was a problem hiding this comment.
style: magic numbers 1_500 and 15_000 should be extracted as named constants at the top of the file
Suggested change
| refetchInterval: (query) => { | |
| const hasPending = (query.state.data?.records.length ?? 0) > 0; | |
| return hasPending ? 1_500 : 15_000; | |
| }, | |
| const REFRESH_INTERVAL_PROCESSING = 1_500; | |
| const REFRESH_INTERVAL_IDLE = 15_000; | |
| // ... | |
| refetchInterval: (query) => { | |
| const hasPending = (query.state.data?.records.length ?? 0) > 0; | |
| return hasPending ? REFRESH_INTERVAL_PROCESSING : REFRESH_INTERVAL_IDLE; | |
| }, |
Context Used: Context from dashboard - Guidelines for writing clean, maintainable, and human-readable code. Apply these rules when writing ... (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/web/src/app/app.agentset.ai/(dashboard)/[slug]/[namespaceSlug]/documents/use-pending-jobs.ts
Line: 44:47
Comment:
**style:** magic numbers `1_500` and `15_000` should be extracted as named constants at the top of the file
```suggestion
const REFRESH_INTERVAL_PROCESSING = 1_500;
const REFRESH_INTERVAL_IDLE = 15_000;
// ...
refetchInterval: (query) => {
const hasPending = (query.state.data?.records.length ?? 0) > 0;
return hasPending ? REFRESH_INTERVAL_PROCESSING : REFRESH_INTERVAL_IDLE;
},
```
**Context Used:** Context from `dashboard` - Guidelines for writing clean, maintainable, and human-readable code. Apply these rules when writing ... ([source](https://app.greptile.com/review/custom-context?memory=ae3f5924-b837-4792-9dae-0bd929e9f8dd))
<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>
How can I resolve this? If you propose a fix, please make it concise.- Add isProcessing parameter to useDocuments hook - Update useJobsStatus to use dynamic refetchInterval based on pending jobs - Pass isProcessing from jobsStatus to useDocuments in page component - Refresh every 5s when processing, 15s when idle
addce6b to
d871200
Compare
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
Improves UX by refreshing data more frequently (every 1.5s instead of 15s) ONLY when jobs are being processed, so users see updates faster.
Changes
isProcessingparameter that controls refresh intervalrefetchIntervalthat speeds up when pending jobs are detectedisProcessingstate touseDocumentsBehavior
This ensures the UI updates quickly while documents are being processed, then returns to normal polling to reduce unnecessary requests.
Note: This PR is based on
feat/documents-processing-calloutand should be merged after it.Greptile Summary
This PR implements adaptive polling intervals to improve UX when jobs are processing. When pending jobs are detected, the refresh interval speeds up from 15s to 1.5s across both job status checks and document queries.
Key Changes:
useJobsStatusnow uses a dynamicrefetchIntervalfunction that checks for pending jobsuseDocumentsaccepts anisProcessingparameter to control its refresh intervalMinor improvement suggested:
1_500,15_000) as named constants to follow clean code guidelinesConfidence Score: 5/5
Important Files Changed
isProcessingparameter to control refetch interval; implementation is straightforward and correctisProcessingstate from jobs status and passes it touseDocumentshook; clean integrationContext used:
dashboard- Guidelines for writing clean, maintainable, and human-readable code. Apply these rules when writing ... (source)