Skip to content

Commit 5a3e191

Browse files
committed
fix: optimize findFirst
1 parent 31d2626 commit 5a3e191

File tree

1 file changed

+7
-3
lines changed
  • packages/runtime/src/client/crud/operations

1 file changed

+7
-3
lines changed

packages/runtime/src/client/crud/operations/find.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,19 @@ export class FindOperationHandler<Schema extends SchemaDef> extends BaseOperatio
88
const normalizedArgs = this.normalizeArgs(args);
99

1010
// parse args
11-
const parsedArgs = validateArgs
11+
const parsedArgs = (validateArgs
1212
? this.inputValidator.validateFindArgs(this.model, operation === 'findUnique', normalizedArgs)
13-
: normalizedArgs;
13+
: normalizedArgs) as FindArgs<Schema, GetModels<Schema>, true>;
14+
15+
if(operation === 'findFirst'){
16+
parsedArgs.take = 1;
17+
}
1418

1519
// run query
1620
const result = await this.read(
1721
this.client.$qb,
1822
this.model,
19-
parsedArgs as FindArgs<Schema, GetModels<Schema>, true>,
23+
parsedArgs,
2024
);
2125

2226
const finalResult = operation === 'findMany' ? result : (result[0] ?? null);

0 commit comments

Comments
 (0)