Skip to content

feat: refactor document fetching and improve comment batching#848

Merged
MODSetter merged 2 commits intomainfrom
dev
Feb 28, 2026
Merged

feat: refactor document fetching and improve comment batching#848
MODSetter merged 2 commits intomainfrom
dev

Conversation

@MODSetter
Copy link
Owner

@MODSetter MODSetter commented Feb 28, 2026

Description

Motivation and Context

FIX #

Screenshots

API Changes

  • This PR includes API changes

Change Type

  • Bug fix
  • New feature
  • Performance improvement
  • Refactoring
  • Documentation
  • Dependency/Build system
  • Breaking change
  • Other (specify):

Testing Performed

  • Tested locally
  • Manual/QA verification

Checklist

  • Follows project coding standards and conventions
  • Documentation updated as needed
  • Dependencies updated as needed
  • No lint/build errors or new warnings
  • All relevant tests are passing

High-level PR Summary

This PR refactors document fetching to use React Query for better caching and deduplication, eliminating redundant API calls when multiple components mount. It also fixes a race condition in comment batching by introducing a promise-based gate mechanism (_batchReady) that ensures individual queries wait for batch prefetch logic to initialize before deciding whether to piggyback or fetch independently. The connector popup component is updated to use a lightweight cached endpoint for document type counts instead of the previous Electric SQL approach.

⏱️ Estimated Review Time: 15-30 minutes

💡 Review Order Suggestion
Order File Path
1 surfsense_web/lib/query-client/client.ts
2 surfsense_web/hooks/use-documents.ts
3 surfsense_web/hooks/use-comments.ts
4 surfsense_web/components/assistant-ui/connector-popup.tsx

Need help? Join our Discord

Analyze latest changes

- Replaced the useDocuments hook with React Query for better caching and deduplication of document requests.
- Updated the ConnectorIndicator component to fetch document type counts using a new atom for real-time updates.
- Enhanced the useComments hook to manage batch requests more effectively, reducing race conditions and improving performance.
- Set default query options in the query client to optimize stale time and refetch behavior.
@vercel
Copy link

vercel bot commented Feb 28, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
surf-sense-frontend Building Building Preview, Comment Feb 28, 2026 9:56am

Request Review

@MODSetter MODSetter merged commit f2f15f6 into main Feb 28, 2026
5 of 7 checks passed
Copy link

@recurseml recurseml bot left a comment

Choose a reason for hiding this comment

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

Review by RecurseML

🔍 Review performed on 0a28014..cc64e18

✨ No bugs found, your code is sparkling clean

✅ Files analyzed, no issues (4)

surfsense_web/components/assistant-ui/connector-popup.tsx
surfsense_web/hooks/use-comments.ts
surfsense_web/hooks/use-documents.ts
surfsense_web/lib/query-client/client.ts

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.

1 participant