fix(feed): clamp public user feed pagination#319
Conversation
Greptile SummaryThis PR fixes pagination on the public user feed endpoint by replacing ad-hoc
Confidence Score: 5/5Safe to merge; the helper logic is correct and the tests accurately verify the clamping contract. The change is narrowly scoped to input parsing: the helper produces correct results for all tested edge cases and the route behaviour is otherwise unchanged. The offset ceiling is generous for the in-memory fetch pattern but is still a strict improvement over the previous uncapped parseInt. No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant Client
participant Route as GET /api/users/[username]/feed
participant Helper as parsePaginationParam
participant DB as Supabase
Client->>Route: "?limit=X&offset=Y"
Route->>Helper: parsePaginationParam(limit, 20, 1, 50)
Helper-->>Route: clamped limit in [1, 50]
Route->>Helper: parsePaginationParam(offset, 0, 0, 100_000)
Helper-->>Route: clamped offset in [0, 100_000]
Route->>DB: profiles.select().eq(username).single()
DB-->>Route: "profile | 404"
Route->>DB: posts.range(0, limit+offset-1)
DB-->>Route: rawPosts[]
Route->>DB: post_comments.range(0, limit+offset-1)
DB-->>Route: rawComments[]
Note over Route: merge, sort by created_at, slice(offset, offset+limit)
Route-->>Client: "{ data, pagination: { total, limit, offset } }"
Reviews (2): Last reviewed commit: "test(feed): cover zero public feed limit" | Re-trigger Greptile |
|
Want your agent to iterate on Greptile's feedback? Try greploops. |
Fixes #318.
Summary
limitandoffsetthrough a bounded integer helperTests