Skip to content

Commit

Permalink
skip count call when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
JakNowy committed Apr 12, 2024
1 parent 19e038a commit 3fb3c2e
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions fastcrud/crud/fast_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -1358,8 +1358,7 @@ async def update(
update(db, {'username': 'new_username'}, id__ne=1, allow_multiple=False)
```
"""
total_count = await self.count(db, **kwargs)
if not allow_multiple and total_count > 1:
if not allow_multiple and (total_count := await self.count(db, **kwargs)) > 1:
raise MultipleResultsFound(
f"Expected exactly one record to update, found {total_count}."
)
Expand Down Expand Up @@ -1423,8 +1422,7 @@ async def db_delete(
db_delete(db, username='unique_username', allow_multiple=False)
```
"""
total_count = await self.count(db, **kwargs)
if not allow_multiple and total_count > 1:
if not allow_multiple and (total_count := await self.count(db, **kwargs)) > 1:
raise MultipleResultsFound(
f"Expected exactly one record to delete, found {total_count}."
)
Expand Down

0 comments on commit 3fb3c2e

Please sign in to comment.