Let the database count the entries

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2020-03-19 13:01:34 +01:00
parent e66bc4a8a7
commit cdb36c8ead
No known key found for this signature in database
GPG Key ID: 7076EA9751AACDDA
1 changed files with 6 additions and 2 deletions

View File

@ -228,7 +228,7 @@ class Throttler {
$cutoffTime = $this->getCutoffTimestamp(); $cutoffTime = $this->getCutoffTimestamp();
$qb = $this->db->getQueryBuilder(); $qb = $this->db->getQueryBuilder();
$qb->select('*') $qb->select($qb->func()->count('*', 'attempts'))
->from('bruteforce_attempts') ->from('bruteforce_attempts')
->where($qb->expr()->gt('occurred', $qb->createNamedParameter($cutoffTime))) ->where($qb->expr()->gt('occurred', $qb->createNamedParameter($cutoffTime)))
->andWhere($qb->expr()->eq('subnet', $qb->createNamedParameter($ipAddress->getSubnet()))); ->andWhere($qb->expr()->eq('subnet', $qb->createNamedParameter($ipAddress->getSubnet())));
@ -237,7 +237,11 @@ class Throttler {
$qb->andWhere($qb->expr()->eq('action', $qb->createNamedParameter($action))); $qb->andWhere($qb->expr()->eq('action', $qb->createNamedParameter($action)));
} }
$attempts = count($qb->execute()->fetchAll()); $result = $qb->execute();
$row = $result->fetch();
$result->closeCursor();
$attempts = (int) $row['attempts'];
if ($attempts === 0) { if ($attempts === 0) {
return 0; return 0;