feat: Add API Pagination to Backend List Endpoints
Summary
This PR implements pagination support for all backend list endpoints to prevent performance degradation as the database grows.
Changes Made
- New file: Backend/app/utils/pagination.py - Pagination utility module with parameter validation and response formatting
- Updated: Backend/app/routes/post.py - Added pagination to all 7 GET endpoints:
GET /users/GET /audience-insights/GET /sponsorships/GET /posts/GET /sponsorship-applications/GET /sponsorship-payments/GET /collaborations/
Implementation Details
Query Parameters
All list endpoints now accept:
skip(int, default=0, min=0): Number of records to skip (offset)limit(int, default=50, min=1, max=100): Maximum records to return per page
Response Format
Returns paginated response with metadata:
{
"data": [...],
"skip": 0,
"limit": 50,
"count": 50
}
Summary by CodeRabbit
- New Features
- Added query-based pagination to all GET endpoints: use skip and limit to navigate large result sets.
- Default behavior: skip defaults to 0, limit defaults to 50, and limit is capped (max 100).
- Paginated responses include metadata: returned data, skip, limit, count (returned items), and total_count.
[!WARNING]
Rate limit exceeded
@sharma-sugurthihas exceeded the limit for the number of commits that can be reviewed per hour. Please wait 13 minutes and 24 seconds before requesting another review.β How to resolve this issue?
After the wait time has elapsed, a review can be triggered using the
@coderabbitai reviewcommand as a PR comment. Alternatively, push new commits to this PR.We recommend that you space out your commits to avoid hitting the rate limit.
π¦ How do rate limits work?
CodeRabbit enforces hourly rate limits for each developer per organization.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.
π₯ Commits
Reviewing files that changed from the base of the PR and between d0d260e6ddf7fb1595d5ffaf4ef021a9fdb0cc88 and d4840c9748c8df22bd8fb66e75c4fc9e6be6feb8.
π Files selected for processing (1)
Backend/app/routes/post.py
π Walkthrough
Walkthrough
Adds query-based pagination to seven GET endpoints in Backend/app/routes/post.py and introduces Backend/app/utils/pagination.py with helpers to validate skip/limit and format paginated responses; endpoints now use range-based Supabase queries and return total counts.
Changes
| Cohort / File(s) | Summary |
|---|---|
Pagination Utilities Backend/app/utils/pagination.py |
New module defining DEFAULT_SKIP, DEFAULT_LIMIT, MAX_LIMIT, plus get_pagination_params(skip, limit) and paginate_query(query_result, skip, limit, total_count) for sanitizing params and formatting paginated responses. |
Paginated GET Endpoints Backend/app/routes/post.py |
Updated seven GET routes to accept skip: int = Query(...) and limit: int = Query(...), use get_pagination_params and paginate_query, perform .order("id") and .range(start, end) Supabase queries, and include total_count in responses. |
Sequence Diagram(s)
sequenceDiagram
participant Client
participant API as FastAPI (post routes)
participant Pager as Pagination Utils
participant DB as Supabase
Client->>API: GET /posts?skip=50&limit=25
API->>Pager: get_pagination_params(skip, limit)
Pager-->>API: (start, end, sanitized_skip, sanitized_limit)
API->>DB: query .order("id").range(start, end)
DB-->>API: paged rows
API->>DB: query count
DB-->>API: total_count
API->>Pager: paginate_query(query_result, skip, limit, total_count)
Pager-->>API: {data, skip, limit, count, total_count}
API-->>Client: 200 OK with paginated payload
Estimated code review effort
π― 3 (Moderate) | β±οΈ ~20 minutes
Poem
π°
Hop, skip, and bound I go,
Counting rows in tidy flow,
Limit set and ranges made,
Pages fetch without a braid,
Data served in gentle rows.
π₯ Pre-merge checks | β 2 | β 1
β Failed checks (1 warning)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Docstring Coverage | β οΈ Warning | Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. | Write docstrings for the functions missing them to satisfy the coverage threshold. |
β Passed checks (2 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | β Passed | Check skipped - CodeRabbitβs high-level summary is enabled. |
| Title check | β Passed | The title 'feat: Add API Pagination to Backend List Endpoints' directly and clearly describes the main change: implementing pagination for list endpoints. |
βοΈ Tip: You can configure your own custom pre-merge checks in the settings.
β¨ Finishing Touches
π§ͺ Generate unit tests (beta)
- [ ] Create PR with unit tests
- [ ] Post copyable unit tests in a comment
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands and usage tips.
Please review @Zahnentferner
also fixed some issues that pointed from the review of bot!!!