Skip to content

Convert one exerciseResponses db.scan to pg lookup#2617

Merged
Will-Howard merged 1 commit into
masterfrom
wh-2584-prep-reads-2026-06
Jun 6, 2026
Merged

Convert one exerciseResponses db.scan to pg lookup#2617
Will-Howard merged 1 commit into
masterfrom
wh-2584-prep-reads-2026-06

Conversation

@Will-Howard

Copy link
Copy Markdown
Collaborator

Description

Parcelling this out to reduce the diff of the PR to flip this table to postgres-only (#2616)

Issue

#2580

Developer checklist

@Will-Howard Will-Howard temporarily deployed to wh-2584-prep-reads-2026-06 - bluedot-preview PR #2617 June 6, 2026 09:01 — with Render Destroyed
@coderabbitai

coderabbitai Bot commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@Will-Howard, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 27 minutes and 32 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command 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 include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ea77b7f9-e5e1-4107-903a-603afdd32fd0

📥 Commits

Reviewing files that changed from the base of the PR and between f6c4fb0 and 9a99d52.

📒 Files selected for processing (1)
  • apps/website/src/server/routers/certificates.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch wh-2584-prep-reads-2026-06

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 and usage tips.

@Will-Howard Will-Howard temporarily deployed to wh-2584-prep-reads-2026-06 - bluedot-storybook-preview PR #2617 June 6, 2026 09:01 — with Render Destroyed
@greptile-apps

greptile-apps Bot commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR replaces one db.scan call on exerciseResponseTable with an equivalent direct Drizzle/Postgres query as a stepping stone toward removing the Airtable dependency for that table (#2616). The logic is semantically identical: the original AND [email, OR [exerciseId...]] filter maps cleanly to eq(email) AND inArray(exerciseId, ids).

  • The inArray call is safe because an early-return guard (if (allExercises.length === 0) return false) prevents it from ever receiving an empty array, which would generate invalid SQL.
  • All other lookups in the file (db.scan, db.get, db.getFirst, db.update) are unchanged and remain on the existing hybrid adapter.

Confidence Score: 5/5

Safe to merge — the change is a like-for-like translation of a single filter into a direct Postgres query with no behavioral difference.

The rewritten query is semantically identical to the old db.scan call. The only edge-case risk (inArray receiving an empty array, which generates invalid SQL) is already prevented by the existing allExercises.length === 0 early-return guard. No other logic in the file is touched.

No files require special attention.

Important Files Changed

Filename Overview
apps/website/src/server/routers/certificates.ts Converts the areAllFoaiExercisesComplete exercise-response fetch from db.scan (hybrid Airtable/Postgres) to a direct Drizzle ORM Postgres query using eq + inArray; semantics are preserved and the empty-exercise guard prevents an empty inArray call.

Sequence Diagram

sequenceDiagram
    participant Caller
    participant areAllFoaiExercisesComplete
    participant db_scan as db.scan (Airtable/PG hybrid)
    participant db_pg as db.pg (Drizzle/Postgres)

    Caller->>areAllFoaiExercisesComplete: email
    areAllFoaiExercisesComplete->>db_scan: "scan(exerciseTable, {courseId, status})"
    db_scan-->>areAllFoaiExercisesComplete: allExercises[]
    alt allExercises is empty
        areAllFoaiExercisesComplete-->>Caller: false
    else
        areAllFoaiExercisesComplete->>db_pg: "SELECT WHERE email=? AND exerciseId IN (?)"
        Note over areAllFoaiExercisesComplete,db_pg: Previously: db.scan(exerciseResponseTable, AND/OR filter)
        db_pg-->>areAllFoaiExercisesComplete: exerciseResponses[]
        areAllFoaiExercisesComplete-->>Caller: allExercises.every(id in completedSet)
    end
Loading

Reviews (1): Last reviewed commit: "Convert one exerciseResponses db.scan to..." | Re-trigger Greptile

@Will-Howard Will-Howard merged commit b57df73 into master Jun 6, 2026
7 checks passed
@Will-Howard Will-Howard deleted the wh-2584-prep-reads-2026-06 branch June 6, 2026 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant