Skip to content

Conversation

@svetch
Copy link
Contributor

@svetch svetch commented Sep 1, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Single-result queries now consistently return only one item (e.g., first-match lookups no longer over-fetch); multi-result queries unchanged.
  • Refactor

    • Internal handling of query arguments streamlined to improve reliability and reduce edge cases, with no changes to public behavior or interfaces.

Copilot AI review requested due to automatic review settings September 1, 2025 16:11
@coderabbitai
Copy link

coderabbitai bot commented Sep 1, 2025

Note

Other AI code review bot(s) detected

CodeRabbit 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.

Walkthrough

Refactors find operation handling: initializes parsedArgs with a full FindArgs cast, sets parsedArgs.take = 1 when operation === 'findFirst', passes parsedArgs directly to the read call, and preserves result selection (findMany vs first/null). (34 words)

Changes

Cohort / File(s) Summary
Find operations argument handling
packages/runtime/src/client/crud/operations/find.ts
Casts parsedArgs to FindArgs<Schema, GetModels<Schema>, true> at initialization; adds if (operation === 'findFirst') parsedArgs.take = 1;; passes parsedArgs directly to read; preserves final result selection logic (return many or first/null).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

A rabbit hops through code so neat,
I nudge parsedArgs to make queries sweet.
Take one for first, keep many intact,
A tiny tweak — behavior exact.
🐇✨


📜 Recent 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.

📥 Commits

Reviewing files that changed from the base of the PR and between 49a6fbf and f749a4b.

📒 Files selected for processing (1)
  • packages/runtime/src/client/crud/operations/find.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/runtime/src/client/crud/operations/find.ts
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

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

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

Copilot AI left a 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: 1 parameter for findFirst operations
  • 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.

Copy link

@coderabbitai coderabbitai bot left a 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.

📥 Commits

Reviewing files that changed from the base of the PR and between 31d2626 and 5a3e191.

📒 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/, and tests/

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.

Copy link

@coderabbitai coderabbitai bot left a 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-provided take; preserve negative-direction semantics.

Unconditionally setting take = 1 breaks use cases like take: -1 with findFirst. 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 flag take/orderBy on findUnique. It’s fine if you rely on runtime validation, but consider keeping the cast at the read call (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.

📥 Commits

Reviewing files that changed from the base of the PR and between 5a3e191 and 49a6fbf.

📒 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/, and tests/

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 simplifies the call.

@ymc9 ymc9 changed the base branch from main to dev September 2, 2025 00:47
Update packages/runtime/src/client/crud/operations/find.ts

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Member

@ymc9 ymc9 left a 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.

@ymc9 ymc9 merged commit 2eb4ad3 into zenstackhq:dev Sep 3, 2025
2 checks passed
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.

2 participants