From a49c00b5b5cc87a6f9acf0f53da1f44dd5d8b9f8 Mon Sep 17 00:00:00 2001
From: matthiasgrimm <matthiasgrimm@users.sourceforge.net>
Date: Thu, 26 Jan 2006 21:57:15 +0100
Subject: [PATCH] MySQL getUserCount() optimizsation

The function getUserCount() uses SQL_CALC_FOUND_ROWS now if
MySQL v4.0 or later is found. This will speed up this query
with big user tables.

darcs-hash:20060126205715-7ef76-e3a7009ad6be3659002b562bc055e4fe1cbd904a.gz
---
 inc/auth/mysql.class.php | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/inc/auth/mysql.class.php b/inc/auth/mysql.class.php
index 2642ebd4c..cc53ab073 100644
--- a/inc/auth/mysql.class.php
+++ b/inc/auth/mysql.class.php
@@ -242,9 +242,16 @@ class auth_mysql extends auth_basic {
       
       if($this->_openDB()) {
         $sql = $this->_createSQLFilter($this->cnf['getUsers'], $filter);
-        $result = $this->_queryDB($sql);
-        if ($result)
-            $rc = count($result);
+        
+        if ($this->dbver >= 4) {
+          $sql = substr($sql, 6);  /* remove 'SELECT' or 'select' */
+          $sql = "SELECT SQL_CALC_FOUND_ROWS".$sql." LIMIT 1";
+          $this->_queryDB($sql);
+          $result = $this->_queryDB("SELECT FOUND_ROWS()");
+          $rc = $result[0]['FOUND_ROWS()'];
+        } else if (($result = $this->_queryDB($sql)))
+          $rc = count($result);
+          
         $this->_closeDB();
       }
       return $rc;
-- 
GitLab