Skip to content

feat: added database pagination#725

Open
madsysharma wants to merge 12 commits into
knoxiboy:mainfrom
madsysharma:feat/db-level-pagination
Open

feat: added database pagination#725
madsysharma wants to merge 12 commits into
knoxiboy:mainfrom
madsysharma:feat/db-level-pagination

Conversation

@madsysharma

@madsysharma madsysharma commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

User description

Description

Database-level pagination (ORDER BY/LIMIT/OFFSET), the reply-count subquery, and the total count are already on main, so the JS-memory pagination the issue describes is already resolved. This PR finishes the remaining items:

  1. Like/bookmark status via EXISTS subqueries: folded into the main query instead of two extra per-request round-trips.
  2. Keyset (cursor) pagination: an opt-in, backward-compatible alternative to offset for recency-sorted infinite scroll.
  3. Composite indexes: (classroomId, createdAt), (classroomId, type), (classroomId, isSolved) plus a migration.

Related Issue

Closes #319.

Type of Change

  • Performance improvement
  • Database (schema/index + migration)
  • Test addition

What changed

EXISTS subqueries (src/app/api/doubts/route.ts)

Previously hasLiked/hasBookmarked were computed with two additional queries (SELECT doubtId FROM likes/bookmarks WHERE userEmail = ?) and Set.has() in JS. They're now resolved inline on the main query:

hasLiked:      EXISTS (SELECT 1 FROM likes     WHERE doubtId = d.id AND userEmail = $email)
hasBookmarked: EXISTS (SELECT 1 FROM bookmarks WHERE doubtId = d.id AND userEmail = $email)

Anonymous viewers resolve to false. Both fields were already booleans in the response; they're now always present (logged-out users get false instead of undefined: same truth value, so no client breakage).

Keyset cursor pagination (src/lib/pagination.ts and route)

A new optional cursor query param enables keyset paging:

WHERE (createdAt, id) < (cursorCreatedAt, cursorId)  ORDER BY createdAt DESC, id DESC  LIMIT n

This is O(log n) on the new (classroomId, createdAt) index rather than O(n) at deep offsets. It is opt-in and conservative: honored only for the default recency sort with no search, where (createdAt, id) is a stable monotonic key. Offset/page pagination is unchanged and remains the default; pinned-first ordering and the popular/most-replied/search-rank sorts keep using offset (their ordering isn't a monotonic keyset). The response gains an additive nextCursor for recency feeds (returned whether the request used offset or cursor, so clients can switch to cursor for deep scroll). encodeCursor / decodeCursor live in src/lib/pagination.ts; decodeCursor returns null for any malformed/garbage input so the route safely falls back to offset.

Composite indexes (src/configs/schema.ts + drizzle/0016_doubts_composite_indexes.sql)

Added (classroomId, createdAt), (classroomId, type), (classroomId, isSolved) to support the feed's filter + recency-ordering access pattern. The migration is a hand-written idempotent CREATE INDEX IF NOT EXISTS file matching the repo's existing manual-migration convention (e.g. 0009_query_indexes.sql, run by drizzle/migrate.ts).

Backward compatibility

The response object is preserved (doubts, hasMore, totalCount, page, limit) with nextCursor added. Existing offset/page/limit params behave exactly as before. No removed fields.

Testing

  • src/__tests__/lib/pagination.test.ts: cursor round-trips (Date / ISO / epoch inputs), produces an opaque base64 token, and returns null for null/empty/garbage/non-numeric-id/invalid-date inputs (safe offset fallback).
  • Existing doubts.test.ts / doubts-id.test.ts pass unchanged.
  • npx tsc --noEmit introduces no new errors, and the full suite shows no new failures, versus a clean main checkout. (Upstream main currently has 2 pre-existing tsc errors and 4 failing suites unrelated to this PR: verified identical before/after.)

Notes / scope

  • rooms/route.ts is intentionally left out to keep this PR focused; it does not exhibit the fetch-all-then-slice pattern the issue targets. Happy to do it as a follow-up.
  • Migration: drizzle/0016_doubts_composite_indexes.sql (idempotent CREATE INDEX IF NOT EXISTS) plus a _journal.json entry (idx 16) so the migration-integrity test added by PR fix(devops): resolve 14 duplicate version-number migration files in drizzle/ #722 passes. npx drizzle-kit generate still cannot run non-interactively on main (a pre-existing schema.ts <-> snapshot column conflict prompts for input), so that gate remains red independent of this PR; the hand-written migration follows the repo's manual approach.
    Note: PR [ADVANCED] Refactor Video Generation Pipeline to Async Background Job with Progress Tracking #321 also adds a 0016_* migration; whichever lands second must bump to 0017 (filename + journal idx) to keep numbers unique.
  • Layers on the new anonymization (PR fix: anonymized author ids in doubt apis #703): that PR (now on main) wraps the doubts responses in toPublicDoubt but kept the two extra like/bookmark queries. This PR replaces those with the EXISTS subqueries on the main SELECT; toPublicDoubt preserves the resulting hasLiked/hasBookmarked fields, so the two changes compose cleanly.

Checklist

  • No new dependencies; schema change ships with a migration
  • Backward-compatible response shape
  • Added tests for the new cursor helper
  • Linked the related issue

Summary by CodeRabbit

  • New Features

    • Added cursor-based pagination to the newest doubts feed (keyset pagination).
    • Extended the doubts feed response with nextCursor and improved hasMore behavior.
    • Added performance indexes to optimize classroom-scoped doubts feed sorting and filtering.
  • Bug Fixes

    • Reduced per-doubt follow-up lookups by inlining like/bookmark status in the main query.
    • Improved error messaging for classroom validation and authorization scenarios.
  • Tests

    • Added pagination cursor helper tests and updated related API/handler tests.

CodeAnt-AI Description

Speed up doubts feed loading and add cursor-based pagination

What Changed

  • The doubts feed can now load the next page with an opaque cursor, which keeps infinite scroll stable without relying on deep offsets
  • Like and bookmark status now comes back with each doubt in the main response, including false for signed-out viewers
  • New database indexes support classroom, type, and solved-state filtering while keeping recency sorting fast
  • Added tests for cursor encoding/decoding and updated existing tests to cover the new feed behavior

Impact

✅ Faster infinite scroll on large doubts feeds
✅ Fewer extra lookups per feed request
✅ Quicker classroom-filtered feed pages

💡 Usage Guide

Checking Your Pull Request

Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

Talking to CodeAnt AI

Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

Preserve Org Learnings with CodeAnt

You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

Check Your Repository Health

To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.

@codeant-ai

codeant-ai Bot commented Jun 30, 2026

Copy link
Copy Markdown

CodeAnt AI is reviewing your PR.

@vercel

vercel Bot commented Jun 30, 2026

Copy link
Copy Markdown

@madsysharma is attempting to deploy a commit to the Karan Mani Tripathi 's projects Team on Vercel.

A member of the Team first needs to authorize it.

@codeant-ai

codeant-ai Bot commented Jun 30, 2026

Copy link
Copy Markdown

Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@github-actions github-actions Bot added gssoc'26 GSSoC program issue level:critical Critical level task type:bug Bug fix type:performance Performance improvement review-needed labels Jun 30, 2026
@github-actions github-actions Bot requested a review from knoxiboy June 30, 2026 21:35
@github-actions

Copy link
Copy Markdown

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Adds cursor-based pagination for the doubts feed, with new cursor helpers, query-path branching in GET /api/doubts, inline like/bookmark flags, and matching composite indexes plus migration metadata. Several test suites were updated for the new cursor and Jest-based behavior.

Changes

Doubts Feed Pagination

Layer / File(s) Summary
Cursor helpers and validation
src/lib/pagination.ts, src/__tests__/lib/pagination.test.ts
Adds DecodedCursor, encodeCursor, and decodeCursor for opaque (createdAt, id) cursor tokens, plus tests for round-tripping and invalid input handling.
Doubts feed cursor pagination
src/app/api/doubts/route.ts
Adds cursor parsing, keyset filtering and ordering, inline EXISTS flags for likes/bookmarks, and nextCursor/hasMore response handling.
Schema and migration indexes
src/configs/schema.ts, drizzle/0016_doubts_composite_indexes.sql, drizzle/meta/_journal.json
Adds composite doubts indexes in schema, a matching SQL migration, and the journal entry for the new migration.

Test Updates

Layer / File(s) Summary
Doubts accept route test migration
src/app/api/doubts/[id]/accept/route.test.ts
Switches the accept-route test harness to Jest and updates DB, Drizzle, and assertion mocks around idempotent acceptance behavior.
Supporting assertion updates
src/__tests__/api/teacher-insights.test.ts, src/__tests__/inngest/digest-functions.test.ts, src/__tests__/lib/anonymity.test.ts
Adjusts error expectations, Inngest handler invocation, and environment cleanup assertions to match revised behavior.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

  • knoxiboy/DoubtDesk#389: Both PRs modify src/app/api/doubts/route.ts to move doubts filtering/sorting/pagination logic into SQL queries rather than in-memory processing.
  • knoxiboy/DoubtDesk#568: Both PRs change the doubts GET endpoint's pagination behavior/metadata and update related pagination tests.
  • knoxiboy/DoubtDesk#580: Both PRs modify the same GET query construction/orderBy logic in src/app/api/doubts/route.ts.

Suggested labels: type:testing, quality:clean

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR adds doubts-feed cursor pagination and indexes, but it does not cover rooms API, reply count, or tag subquery optimizations from #319. Add the remaining reply count/tag query optimizations and apply the pagination/index pattern to the rooms API as requested in #319.
Out of Scope Changes check ⚠️ Warning Several test-only edits touch teacher-insights, digest-functions, anonymity, and accept-route tests without a clear link to the doubts pagination objective. Remove unrelated test changes or split them into separate PRs, keeping this one focused on doubts-feed pagination and supporting schema work.
✅ Passed checks (3 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately reflects the main change: adding database-level pagination.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codeant-ai codeant-ai Bot added the size:L This PR changes 100-499 lines, ignoring generated files label Jun 30, 2026
@github-actions github-actions Bot removed the size:L This PR changes 100-499 lines, ignoring generated files label Jun 30, 2026
@madsysharma

Copy link
Copy Markdown
Contributor Author

Hi @knoxiboy , please review this PR. Thank you.

Comment thread drizzle/0016_doubts_composite_indexes.sql
Comment thread src/app/api/doubts/route.ts Outdated
Comment thread src/lib/pagination.ts
@codeant-ai

codeant-ai Bot commented Jun 30, 2026

Copy link
Copy Markdown

CodeAnt AI finished reviewing your PR.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/app/api/doubts/route.ts`:
- Around line 230-250: In the cursor pagination path of doubts/route.ts, the
current use of query.limit(limit) in the useCursor branch can miscompute hasMore
and produce a dead next cursor when the last page is exactly full. Update the
cursor-mode logic in the doubts query and the subsequent nextCursor/hasMore
handling to fetch limit + 1 rows, use the extra row to decide whether another
page exists, then trim the results back to limit before returning and
constructing the cursor.
- Around line 210-228: The pagination logic in the doubts route mixes two
different orderings: offset mode uses pinned-first sorting while cursor mode
resumes with only createdAt/id, so do not emit nextCursor from responses ordered
by the offset path. Update the route handler in the doubts API so nextCursor is
only returned when useCursor is already true, or change the offset and cursor
branches to share the exact same ordering in orderByFields and the cursor
creation logic. Make the fix around the pagination response near the nextCursor
handling to keep the ordering consistent.

In `@src/configs/schema.ts`:
- Around line 215-228: The new filtered indexes in schema.ts for
classroomTypeIndex and classroomSolvedIndex do not include the recency key used
by the feed query. Update the index definitions in the doubts schema so the
composite keys match GET /api/doubts filtering and ordering, using classroomId +
type/isSolved + createdAt with createdAt last; then mirror the same composite
shape in drizzle/0016_doubts_composite_indexes.sql so the migration matches the
schema.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 01ae8a17-39e3-407d-bc85-01f1603becb7

📥 Commits

Reviewing files that changed from the base of the PR and between 0e8d658 and 5efc249.

📒 Files selected for processing (6)
  • drizzle/0016_doubts_composite_indexes.sql
  • drizzle/meta/_journal.json
  • src/__tests__/lib/pagination.test.ts
  • src/app/api/doubts/route.ts
  • src/configs/schema.ts
  • src/lib/pagination.ts

Comment thread src/app/api/doubts/route.ts
Comment thread src/app/api/doubts/route.ts Outdated
Comment thread src/configs/schema.ts
@knoxiboy

knoxiboy commented Jul 2, 2026

Copy link
Copy Markdown
Owner

@madsysharma look into ci test failures and try to fix that

madsysharma and others added 8 commits July 3, 2026 09:17
Refactor cursor-based pagination logic for clarity and correctness, ensuring proper handling of cursor tokens and sentinel rows.
Fix missing newline at the end of the file.
Added a newline at the end of the pagination test file.
Added composite indexes for filtering and ordering doubts feed.
@madsysharma madsysharma force-pushed the feat/db-level-pagination branch from 56d6547 to 743a40c Compare July 3, 2026 16:47
@codeant-ai

codeant-ai Bot commented Jul 3, 2026

Copy link
Copy Markdown

CodeAnt AI is running Incremental review

@codeant-ai

codeant-ai Bot commented Jul 3, 2026

Copy link
Copy Markdown

Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@codeant-ai codeant-ai Bot added the size:L This PR changes 100-499 lines, ignoring generated files label Jul 3, 2026
@github-actions github-actions Bot removed the size:L This PR changes 100-499 lines, ignoring generated files label Jul 3, 2026
@codeant-ai

codeant-ai Bot commented Jul 3, 2026

Copy link
Copy Markdown

CodeAnt AI Incremental review completed.

@madsysharma

madsysharma commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

Hi @knoxiboy , have included fixes for the CI failures - although the remaining failure is coming from DB migration (duplicate ID), which has nothing to do with my changes. Please review this new PR. Thank you.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
src/app/api/doubts/[id]/accept/route.test.ts (1)

40-62: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Make the select mock branch on query shape, not call count.
mockSelectCallCount only works while the route keeps the same two selects in the same order; if another select is added or the lookups are reordered, the test will return the wrong fixture instead of failing. Key off the .from() target (or another query-specific field) so each lookup resolves to the right response.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/app/api/doubts/`[id]/accept/route.test.ts around lines 40 - 62, The
select mock in the doubted accept route test is tied to invocation order via
mockSelectCallCount, so it can return the wrong fixture if the route changes its
select sequence. Update the jest.mock for db.select to branch on query shape
instead of call count, using the .from() target or another query-specific signal
so the doubt lookup and reply lookup each resolve to the correct mocked result.
Keep the change localized in the mock helpers like makeSelectChain and db.select
so the test stays stable if queries are reordered or additional selects are
added.
src/__tests__/inngest/digest-functions.test.ts (1)

64-72: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚖️ Poor tradeoff

Avoid calling the internal .fn handler
createFunction() doesn’t document .fn as a public API, so this test is coupled to an Inngest internal and may break on SDK upgrades. Prefer a testable wrapper or the official Inngest test engine instead of reaching into the returned object.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/__tests__/inngest/digest-functions.test.ts` around lines 64 - 72, The
test helper runHandler is reaching into Inngest’s internal .fn property, which
couples the test to a non-public API. Refactor
src/__tests__/inngest/digest-functions.test.ts to avoid invoking
createFunction() output via .fn; instead test through an exported wrapper around
the handler logic or use the official Inngest test engine/SDK test utilities.
Keep the handler-specific assertions in the digest function tests, but route
execution through supported interfaces such as the function-under-test itself or
a helper around makeStep rather than the internal function object.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/__tests__/inngest/digest-functions.test.ts`:
- Around line 64-72: The test helper runHandler is reaching into Inngest’s
internal .fn property, which couples the test to a non-public API. Refactor
src/__tests__/inngest/digest-functions.test.ts to avoid invoking
createFunction() output via .fn; instead test through an exported wrapper around
the handler logic or use the official Inngest test engine/SDK test utilities.
Keep the handler-specific assertions in the digest function tests, but route
execution through supported interfaces such as the function-under-test itself or
a helper around makeStep rather than the internal function object.

In `@src/app/api/doubts/`[id]/accept/route.test.ts:
- Around line 40-62: The select mock in the doubted accept route test is tied to
invocation order via mockSelectCallCount, so it can return the wrong fixture if
the route changes its select sequence. Update the jest.mock for db.select to
branch on query shape instead of call count, using the .from() target or another
query-specific signal so the doubt lookup and reply lookup each resolve to the
correct mocked result. Keep the change localized in the mock helpers like
makeSelectChain and db.select so the test stays stable if queries are reordered
or additional selects are added.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 7f19114c-a3c5-400a-9c38-7f736bcddaa3

📥 Commits

Reviewing files that changed from the base of the PR and between 5efc249 and 743a40c.

📒 Files selected for processing (10)
  • drizzle/0016_doubts_composite_indexes.sql
  • drizzle/meta/_journal.json
  • src/__tests__/api/teacher-insights.test.ts
  • src/__tests__/inngest/digest-functions.test.ts
  • src/__tests__/lib/anonymity.test.ts
  • src/__tests__/lib/pagination.test.ts
  • src/app/api/doubts/[id]/accept/route.test.ts
  • src/app/api/doubts/route.ts
  • src/configs/schema.ts
  • src/lib/pagination.ts
🚧 Files skipped from review as they are similar to previous changes (6)
  • src/tests/lib/pagination.test.ts
  • src/lib/pagination.ts
  • drizzle/meta/_journal.json
  • drizzle/0016_doubts_composite_indexes.sql
  • src/configs/schema.ts
  • src/app/api/doubts/route.ts

@knoxiboy knoxiboy left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good just resolve merge conflicts

@codeant-ai

codeant-ai Bot commented Jul 5, 2026

Copy link
Copy Markdown

CodeAnt AI is running Incremental review

@codeant-ai

codeant-ai Bot commented Jul 5, 2026

Copy link
Copy Markdown

Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@madsysharma

Copy link
Copy Markdown
Contributor Author

Hi @knoxiboy , have resolved the merge conflicts. Please review this PR. Thanks.

@codeant-ai codeant-ai Bot added the size:L This PR changes 100-499 lines, ignoring generated files label Jul 5, 2026
@github-actions github-actions Bot removed the size:L This PR changes 100-499 lines, ignoring generated files label Jul 5, 2026
@codeant-ai

codeant-ai Bot commented Jul 5, 2026

Copy link
Copy Markdown

CodeAnt AI Incremental review completed.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@drizzle/meta/_journal.json`:
- Around line 21-22: The migration journal JSON is invalid because the entry
objects in _journal.json are not separated by a comma. Update the journal
entries around the affected objects so each migration record in the array/list
is properly comma-delimited, preserving the existing schema used by Drizzle’s
migration runner. Verify the file parses as valid JSON after adjusting the
sequence around the 0016_doubts_composite_indexes and 0017_video_jobs entries.

In `@src/app/api/doubts/`[id]/accept/route.test.ts:
- Around line 40-41: Remove the duplicate module-scope mockSelectCallCount
declaration in the route.test setup so the test file loads cleanly. Keep a
single shared counter for the select mock and make sure the mock implementation
and any reset logic in the test cases reference that one declaration, using the
existing mockSelectCallCount symbol to locate the affected setup.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: aea7b663-0a31-4ff3-b27a-309563a8ae68

📥 Commits

Reviewing files that changed from the base of the PR and between 743a40c and 4e6e456.

📒 Files selected for processing (6)
  • drizzle/meta/_journal.json
  • src/__tests__/lib/anonymity.test.ts
  • src/app/api/doubts/[id]/accept/route.test.ts
  • src/app/api/doubts/route.ts
  • src/configs/schema.ts
  • src/lib/pagination.ts
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/configs/schema.ts
  • src/tests/lib/anonymity.test.ts
  • src/lib/pagination.ts
  • src/app/api/doubts/route.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Inline review comments failed to post. This is likely due to GitHub's internal server error or limits when posting large numbers of comments. If you are seeing this consistently it is likely a permissions issue. Please check "Moderation" -> "Code review limits" under your organization settings.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@drizzle/meta/_journal.json`:
- Around line 21-22: The migration journal JSON is invalid because the entry
objects in _journal.json are not separated by a comma. Update the journal
entries around the affected objects so each migration record in the array/list
is properly comma-delimited, preserving the existing schema used by Drizzle’s
migration runner. Verify the file parses as valid JSON after adjusting the
sequence around the 0016_doubts_composite_indexes and 0017_video_jobs entries.

In `@src/app/api/doubts/`[id]/accept/route.test.ts:
- Around line 40-41: Remove the duplicate module-scope mockSelectCallCount
declaration in the route.test setup so the test file loads cleanly. Keep a
single shared counter for the select mock and make sure the mock implementation
and any reset logic in the test cases reference that one declaration, using the
existing mockSelectCallCount symbol to locate the affected setup.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: aea7b663-0a31-4ff3-b27a-309563a8ae68

📥 Commits

Reviewing files that changed from the base of the PR and between 743a40c and 4e6e456.

📒 Files selected for processing (6)
  • drizzle/meta/_journal.json
  • src/__tests__/lib/anonymity.test.ts
  • src/app/api/doubts/[id]/accept/route.test.ts
  • src/app/api/doubts/route.ts
  • src/configs/schema.ts
  • src/lib/pagination.ts
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/configs/schema.ts
  • src/tests/lib/anonymity.test.ts
  • src/lib/pagination.ts
  • src/app/api/doubts/route.ts
🛑 Comments failed to post (2)
drizzle/meta/_journal.json (1)

21-22: 🗄️ Data Integrity & Integration | 🔴 Critical | ⚡ Quick win

Invalid JSON: missing comma breaks the migration journal.

Line 21's entry object is not followed by a comma before line 22's entry object begins, making the whole file invalid JSON. Static analysis confirms this parse error. Drizzle's migration runner relies on this file to track applied migrations — an invalid JSON file will hard-fail any migration command.

🐛 Proposed fix
-    { "idx": 16, "version": "7", "when": 1781400000000, "tag": "0016_doubts_composite_indexes", "breakpoints": true }
+    { "idx": 16, "version": "7", "when": 1781400000000, "tag": "0016_doubts_composite_indexes", "breakpoints": true },
     { "idx": 17, "version": "7", "when": 1781400000000, "tag": "0017_video_jobs", "breakpoints": true }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

    { "idx": 16, "version": "7", "when": 1781400000000, "tag": "0016_doubts_composite_indexes", "breakpoints": true },
    { "idx": 17, "version": "7", "when": 1781400000000, "tag": "0017_video_jobs", "breakpoints": true }
🧰 Tools
🪛 Biome (2.5.1)

[error] 22-22: expected , but instead found {

(parse)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@drizzle/meta/_journal.json` around lines 21 - 22, The migration journal JSON
is invalid because the entry objects in _journal.json are not separated by a
comma. Update the journal entries around the affected objects so each migration
record in the array/list is properly comma-delimited, preserving the existing
schema used by Drizzle’s migration runner. Verify the file parses as valid JSON
after adjusting the sequence around the 0016_doubts_composite_indexes and
0017_video_jobs entries.

Source: Linters/SAST tools

src/app/api/doubts/[id]/accept/route.test.ts (1)

40-41: 📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
rg -n 'mockSelectCallCount' src/app/api/doubts/\[id\]/accept/route.test.ts

Repository: knoxiboy/DoubtDesk

Length of output: 391


🏁 Script executed:

#!/bin/bash
sed -n '1,190p' src/app/api/doubts/\[id\]/accept/route.test.ts | cat -n

Repository: knoxiboy/DoubtDesk

Length of output: 8038


Remove the duplicate mockSelectCallCount declaration. The counter is used in the mock and reset in tests, but it’s declared twice at module scope, which breaks the file before it runs.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/app/api/doubts/`[id]/accept/route.test.ts around lines 40 - 41, Remove
the duplicate module-scope mockSelectCallCount declaration in the route.test
setup so the test file loads cleanly. Keep a single shared counter for the
select mock and make sure the mock implementation and any reset logic in the
test cases reference that one declaration, using the existing
mockSelectCallCount symbol to locate the affected setup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc'26 GSSoC program issue level:critical Critical level task quality : needs-work review-needed size/l type:bug Bug fix type:performance Performance improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ADVANCED] Implement Database-Level Pagination with Cursor-Based Navigation for Doubts Feed

2 participants