-
-
Notifications
You must be signed in to change notification settings - Fork 11
fix: optimize findFirst #229
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
Conversation
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. WalkthroughRefactors find operation handling: initializes Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 💡 Knowledge Base configuration:
You can enable these sources in your CodeRabbit configuration. 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
✨ Finishing Touches
🧪 Generate 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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
Status, Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR optimizes the findFirst operation by automatically setting take: 1 to limit the query to only return one record, improving performance by avoiding unnecessary data retrieval.
Key Changes
- Added automatic
take: 1parameter forfindFirstoperations - Refactored type casting to use a more direct approach
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/runtime/src/client/crud/operations/find.ts (1)
11-14: Broader cast may hide per-operation constraints; consider narrowing by operation.Casting to FindArgs<Schema, GetModels, true> for all ops (including findUnique) can mask invalid fields when validateArgs=false (e.g., stray sort/take leaking into a unique query). If the query builder truly accepts a collection-shaped args object for every op, fine; otherwise, narrow by operation.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
packages/runtime/src/client/crud/operations/find.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
{packages,samples,tests}/**
📄 CodeRabbit inference engine (CLAUDE.md)
Packages are located in
packages/,samples/, andtests/
Files:
packages/runtime/src/client/crud/operations/find.ts
🧬 Code graph analysis (1)
packages/runtime/src/client/crud/operations/find.ts (2)
packages/runtime/src/client/crud-types.ts (1)
FindArgs(646-662)packages/sdk/src/schema/schema.ts (1)
GetModels(108-108)
🔇 Additional comments (1)
packages/runtime/src/client/crud/operations/find.ts (1)
23-23: LGTM: passing parsedArgs directly keeps the read call clean.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
♻️ Duplicate comments (1)
packages/runtime/src/client/crud/operations/find.ts (1)
15-17: Don’t override caller-providedtake; preserve negative-direction semantics.Unconditionally setting
take = 1breaks use cases liketake: -1withfindFirst. Only default it when absent.- if (operation === 'findFirst') { - parsedArgs.take = 1; - } + // Default LIMIT 1 only when caller didn't specify a direction/limit. + if (operation === 'findFirst' && parsedArgs.take == null) { + parsedArgs.take = 1; + } + // Alternatively (TS ≥ 4.0): + // if (operation === 'findFirst') parsedArgs.take ??= 1;
🧹 Nitpick comments (1)
packages/runtime/src/client/crud/operations/find.ts (1)
11-14: Early broad cast weakens compile-time checks for findUnique (optional).Casting to
FindArgs<Schema, GetModels<Schema>, true>up-front means TS won’t flagtake/orderByonfindUnique. It’s fine if you rely on runtime validation, but consider keeping the cast at thereadcall (as before) or narrowing per operation for stronger type safety.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
packages/runtime/src/client/crud/operations/find.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
{packages,samples,tests}/**
📄 CodeRabbit inference engine (CLAUDE.md)
Packages are located in
packages/,samples/, andtests/
Files:
packages/runtime/src/client/crud/operations/find.ts
🧬 Code graph analysis (1)
packages/runtime/src/client/crud/operations/find.ts (2)
packages/runtime/src/client/crud-types.ts (1)
FindArgs(646-662)packages/sdk/src/schema/schema.ts (1)
GetModels(108-108)
🔇 Additional comments (1)
packages/runtime/src/client/crud/operations/find.ts (1)
23-23: LGTM: PassingparsedArgsdirectly simplifies the call.
Update packages/runtime/src/client/crud/operations/find.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @svetch thanks for making the PR. I'll make some amendment to make the validation more robust (and Prisma-consistent) and them merge.
Summary by CodeRabbit
Bug Fixes
Refactor