Conversation
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the 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. 📝 WalkthroughWalkthroughReplaces simple PrismaClient setup with a pg Pool + PrismaPg adapter, adds a non-production global cache for the Pool and Prisma client to persist across reloads, and exposes Changes
Sequence Diagram(s)sequenceDiagram
participant Module as Importing Module
participant ClientFile as src/db/client.ts
participant Pool as pg Pool
participant Prisma as PrismaClient (PrismaPg adapter)
Module->>ClientFile: import { prisma } or default
ClientFile->>Pool: create or reuse global Pool
ClientFile->>Prisma: create or reuse PrismaClient with PrismaPg(pool)
ClientFile-->>Module: return prisma instance
Note right of Prisma: In non-production, both Pool and Prisma cached on global object
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@src/db/client.ts`:
- Around line 29-32: The environment check uses the wrong casing ("Production")
so it never matches NODE_ENV and incorrectly sets globalForPrisma.prisma and
globalForPrisma.pgPool in production; change the check to compare against the
lowercase "production" (or normalize with process.env.NODE_ENV?.toLowerCase())
so the caching block only runs when NODE_ENV !== "production" and avoids adding
references to globalThis in production.
- Around line 24-26: The NODE_ENV check in the DB client config uses
"Development" which won't match conventional lowercase env values; update the
check in the DB client setup (the process.env.NODE_ENV comparison used when
building the logger level array) to use the lowercase string "development" or,
better, compare case-insensitively (e.g., process.env.NODE_ENV?.toLowerCase()
=== "development") so verbose query logging actually enables in development
environments.
🧹 Nitpick comments (1)
src/db/client.ts (1)
11-27: Adapter is created even whenprismais served from cache.When
globalForPrisma.prismaalready exists, thePoolandPrismaPgadapter instantiated on lines 11-17 are unused. Consider moving the pool, adapter, and client creation inside a single guard:Suggested restructure
-const pool = - globalForPrisma.pgPool ?? - new Pool({ - connectionString: process.env.DATABASE_URL, - }); - -const adapter = new PrismaPg(pool); - -export const prisma = - globalForPrisma.prisma ?? - new PrismaClient({ - adapter, - log: - process.env.NODE_ENV === "Development" - ? ["query", "error", "warn"] - : ["error"], - }); +const pool = + globalForPrisma.pgPool ?? + new Pool({ connectionString: process.env.DATABASE_URL }); + +export const prisma = + globalForPrisma.prisma ?? + new PrismaClient({ + adapter: new PrismaPg(pool), + log: + process.env.NODE_ENV === "development" + ? ["query", "error", "warn"] + : ["error"], + });
Summary by CodeRabbit