Skip to content

fix(kb): added proper pagination for documents in kb#937

Merged
waleedlatif1 merged 1 commit intostagingfrom
fix/kb-page
Aug 11, 2025
Merged

fix(kb): added proper pagination for documents in kb#937
waleedlatif1 merged 1 commit intostagingfrom
fix/kb-page

Conversation

@waleedlatif1
Copy link
Collaborator

Summary

added proper pagination for documents in kb. Preivously the api supported pagination but we loaded all documents in the frontend

Type of Change

  • Bug fix

Testing

Tested manually.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

Screenshots/Videos

Screen.Recording.2025-08-11.at.2.09.45.PM.mov

@vercel
Copy link

vercel bot commented Aug 11, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Project Status Preview Comments Updated (UTC)
sim 🔄 Building Visit Preview Aug 11, 2025 9:15pm
1 Skipped Deployment
Project Status Preview Comments Updated (UTC)
docs ⬜️ Skipped Aug 11, 2025 9:15pm

@waleedlatif1 waleedlatif1 merged commit 2a333c7 into staging Aug 11, 2025
4 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/kb-page branch August 11, 2025 21:16
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Greptile Summary

This PR implements proper server-side pagination for documents in the knowledge base, fixing a performance issue where the frontend was loading all documents (up to 10,000) at once despite the API supporting pagination.

The changes span three key files:

  1. use-knowledge.ts: Refactored the hook to use server-side pagination by passing search, limit, and offset parameters directly to the API instead of performing client-side filtering. Removed the MAX_DOCUMENTS_LIMIT constant and simplified the data flow by eliminating client-side useMemo calculations.

  2. store.ts: Updated the caching strategy to match exact request parameters (search, limit, offset) rather than just checking if any cached data exists. This ensures that different pagination requests don't return stale cached results. Also simplified the refreshDocuments function by removing complex document merging logic.

  3. base.tsx: Removed the disabled:cursor-not-allowed CSS class from pagination buttons to improve UX during loading states, keeping only the disabled:opacity-50 for visual feedback.

These changes align the frontend implementation with the existing API pagination capabilities, improving performance and scalability for knowledge bases with large document collections by reducing memory usage and network transfer.

PR Description Notes:

  • Minor typo: "Preivously" should be "Previously"

Confidence score: 3/5

  • This PR addresses a legitimate performance issue but introduces potential regressions in caching behavior and user experience
  • Score reflects concerns about cache invalidation strategy and loss of optimistic UI updates in the store refactoring
  • Pay close attention to stores/knowledge/store.ts where the caching logic changes may cause cache misses and affect document upload UX

3 files reviewed, no comments

Edit Code Review Bot Settings | Greptile

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