]> source.dussan.org Git - nextcloud-server.git/commitdiff
Let the database count the entries
authorJoas Schilling <coding@schilljs.com>
Thu, 19 Mar 2020 12:01:34 +0000 (13:01 +0100)
committerJoas Schilling <coding@schilljs.com>
Wed, 19 Aug 2020 09:20:35 +0000 (11:20 +0200)
Signed-off-by: Joas Schilling <coding@schilljs.com>
lib/private/Security/Bruteforce/Throttler.php

index 8e4850466029288a2ec59243eee405270e4de1e8..e5d3c3503ba23f23028fd2d08cf7f826ac9592bd 100644 (file)
@@ -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;