Skip to content

Commit

Permalink
use exists() instead of count()
Browse files Browse the repository at this point in the history
we only need to check for existence of a record here, not for the actual count, and `exists()` is generally more performant than a count.
  • Loading branch information
browner12 committed Oct 28, 2024
1 parent 5527e72 commit d1d80c3
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/Illuminate/Testing/Constraints/HasInDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ public function __construct(Connection $database, array $data)
*/
public function matches($table): bool
{
return $this->database->table($table)->where($this->data)->count() > 0;
return $this->database->table($table)
->where($this->data)
->exists();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function matches($table): bool
return $this->database->table($table)
->where($this->data)
->whereNull($this->deletedAtColumn)
->count() > 0;
->exists();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function matches($table): bool
return $this->database->table($table)
->where($this->data)
->whereNotNull($this->deletedAtColumn)
->count() > 0;
->exists();
}

/**
Expand Down

0 comments on commit d1d80c3

Please sign in to comment.