Sanity Content Lake API and Frontend Pagination: Total Count Retrieval
0 reputation · 23 Mar 2024, 05:18 UTC
Data Fetching Boundary
Integrating the Sanity Content Lake API with a frontend framework requires efficient pagination to manage large datasets. While the GROQ range slice syntax [start...end] effectively limits the number of documents returned in a single request, the API does not return the total record count within the same response payload as the sliced data.
Implementing a standard pagination UI typically requires both the current page of results and the total number of available documents to calculate page counts or infinite scroll triggers. Fetching these as two separate network requests may introduce latency or synchronization issues between the count and the data slice.
Integration Constraints
- Use of the
cdnendpoint for cached read performance. - Requirement to minimize payload overhead via GROQ projections.
- Need for a consistent total count across paginated requests.
Is there a documented method to retrieve the total count of a filtered dataset and the specific range slice in a single GROQ query? If not, what is the recommended pattern for synchronizing the total count with the data slice to avoid redundant API calls?