From: Joas Schilling Date: Thu, 19 Mar 2020 12:01:34 +0000 (+0100) Subject: Let the database count the entries X-Git-Tag: v20.0.0beta1~40^2~13 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=cdb36c8eadc2b9c2a864941e8d1e585c8f3e18c5;p=nextcloud-server.git Let the database count the entries Signed-off-by: Joas Schilling --- diff --git a/lib/private/Security/Bruteforce/Throttler.php b/lib/private/Security/Bruteforce/Throttler.php index 8e485046602..e5d3c3503ba 100644 --- a/lib/private/Security/Bruteforce/Throttler.php +++ b/lib/private/Security/Bruteforce/Throttler.php @@ -228,7 +228,7 @@ class Throttler { $cutoffTime = $this->getCutoffTimestamp(); $qb = $this->db->getQueryBuilder(); - $qb->select('*') + $qb->select($qb->func()->count('*', 'attempts')) ->from('bruteforce_attempts') ->where($qb->expr()->gt('occurred', $qb->createNamedParameter($cutoffTime))) ->andWhere($qb->expr()->eq('subnet', $qb->createNamedParameter($ipAddress->getSubnet()))); @@ -237,7 +237,11 @@ class Throttler { $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) { return 0;