add new query endpoint for getting document count #495
+60
−4
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.
Looking at the diff, I can provide a clear explanation of this performance optimization:
Pull Request Summary
Performance Optimization: Document Count API Endpoint
Performance Gain: ~90% faster (3724ms → 386ms)
This PR introduces a dedicated lightweight endpoint for fetching document counts, resulting in a 89.6% reduction in response time.
Changes Made:
New Endpoint: Created
/api/materialsTable/fetchDocumentCount.ts.limit(1)instead of counting all documentswithCourseAccessFromRequestFrontend Update: Modified
src/pages/[course_name]/chat.tsxfetchProjectMaterials(which fetches full document data with pagination)fetchDocumentCountendpointPerformance Impact:
Technical Approach:
Instead of fetching and paginating through all documents, the new endpoint uses a simple SQL
LIMIT 1query to check if any documents exist for the course. This dramatically reduces database load and query execution time while providing the same functional result for the UI.