-
Notifications
You must be signed in to change notification settings - Fork 154
feat: added database pagination #725
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
madsysharma
wants to merge
12
commits into
knoxiboy:main
Choose a base branch
from
madsysharma:feat/db-level-pagination
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
6bb7619
feat: added database pagination
madsysharma 85e3920
Improve cursor-based pagination implementation
madsysharma a9dfb20
Add newline at end of pagination.ts
madsysharma 2ca9773
Fix missing newline at end of pagination.test.ts
madsysharma c133bb4
Update classroom indices to include createdAt
madsysharma d16233f
Create composite indexes for doubts feed
madsysharma dd66a98
Update _journal.json
madsysharma 743a40c
ci: addressing build failures
madsysharma 29ce1ce
Fix comment formatting in route.test.ts
madsysharma 8338407
Fix comment formatting in cursor-based pagination
madsysharma 010367f
Fix comment formatting in pagination.ts
madsysharma 4e6e456
Merge branch 'main' into feat/db-level-pagination
madsysharma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| -- Composite indexes for the doubts feed (issue #319). | ||
| -- Support the common filter + recency-ordering access pattern: | ||
| -- WHERE classroomId = ? [AND type = ? | AND isSolved = ?] ORDER BY createdAt DESC | ||
| -- createdAt is the trailing column so the index covers both the filter and the | ||
| -- ORDER BY (no separate sort step). Idempotent so it is safe to re-run via the | ||
| -- manual migrate runner. | ||
| CREATE INDEX IF NOT EXISTS "doubts_classroomId_createdAt_idx" ON "doubts" USING btree ("classroomId", "createdAt");--> statement-breakpoint | ||
| CREATE INDEX IF NOT EXISTS "doubts_classroomId_type_createdAt_idx" ON "doubts" USING btree ("classroomId", "type", "createdAt");--> statement-breakpoint | ||
| CREATE INDEX IF NOT EXISTS "doubts_classroomId_isSolved_createdAt_idx" ON "doubts" USING btree ("classroomId", "isSolved", "createdAt"); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import { encodeCursor, decodeCursor } from "@/lib/pagination"; | ||
|
|
||
| describe("pagination cursor", () => { | ||
| it("round-trips a (createdAt, id) key", () => { | ||
| const createdAt = new Date("2026-06-01T12:34:56.000Z"); | ||
| const cursor = encodeCursor(createdAt, 42); | ||
| const decoded = decodeCursor(cursor); | ||
| expect(decoded).not.toBeNull(); | ||
| expect(decoded!.id).toBe(42); | ||
| expect(decoded!.createdAt.toISOString()).toBe(createdAt.toISOString()); | ||
| }); | ||
|
|
||
| it("accepts a Date, ISO string, or epoch ms as input", () => { | ||
| const iso = "2026-01-15T08:00:00.000Z"; | ||
| const fromDate = decodeCursor(encodeCursor(new Date(iso), 1)); | ||
| const fromString = decodeCursor(encodeCursor(iso, 1)); | ||
| const fromEpoch = decodeCursor(encodeCursor(new Date(iso).getTime(), 1)); | ||
| expect(fromDate!.createdAt.toISOString()).toBe(iso); | ||
| expect(fromString!.createdAt.toISOString()).toBe(iso); | ||
| expect(fromEpoch!.createdAt.toISOString()).toBe(iso); | ||
| }); | ||
|
|
||
| it("produces an opaque base64 string (no raw delimiter leakage)", () => { | ||
| const cursor = encodeCursor(new Date("2026-06-01T00:00:00.000Z"), 7); | ||
| expect(cursor).toMatch(/^[A-Za-z0-9+/]+=*$/); | ||
| expect(cursor).not.toContain("|"); | ||
| }); | ||
|
|
||
| it("returns null for null/empty/garbage input instead of throwing", () => { | ||
| expect(decodeCursor(null)).toBeNull(); | ||
| expect(decodeCursor(undefined)).toBeNull(); | ||
| expect(decodeCursor("")).toBeNull(); | ||
| expect(decodeCursor("not-base64-!!!")).toBeNull(); | ||
| expect(decodeCursor(Buffer.from("garbage-no-separator").toString("base64"))).toBeNull(); | ||
| }); | ||
|
|
||
| it("rejects a cursor with a non-numeric id", () => { | ||
| const bad = Buffer.from("2026-06-01T00:00:00.000Z|abc").toString("base64"); | ||
| expect(decodeCursor(bad)).toBeNull(); | ||
| }); | ||
|
|
||
| it("rejects a cursor with an invalid date", () => { | ||
| const bad = Buffer.from("not-a-date|5").toString("base64"); | ||
| expect(decodeCursor(bad)).toBeNull(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.