From 9ad365e1bde65123cac35b9cb11fea24444b0d3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Nicolaysen=20S=C3=B8rnes?= Date: Mon, 28 May 2007 20:10:49 +0000 Subject: [PATCH] Speedup appData::objectGetEntriesCount() when selecting un-queued entries or we are an admin. --- include/appData.php | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/include/appData.php b/include/appData.php index b5a92eb..00b6448 100644 --- a/include/appData.php +++ b/include/appData.php @@ -203,45 +203,55 @@ class appData $sQuery .= " AND type = '?'"; $hResult = query_parameters($sQuery, $_SESSION['current']->iUserId, $sType); - } else { + } else + { $hResult = query_parameters($sQuery, $_SESSION['current']->iUserId); } } else { - $sQuery = "SELECT COUNT(DISTINCT appData.id) as count FROM appData, + if($sQueued == "true" || $sQueued == "false") + $sAppDataQueued = " AND appData.queued = '$sQueued'"; + + if($sType) + $sSelectType = " AND type = '?'"; + + $sQuery = "(SELECT COUNT(DISTINCT appData.id) as count FROM appData, appFamily, appVersion WHERE appFamily.appId = appVersion.appId AND ( appData.appId = appFamily.appId - OR + ) + AND + appVersion.queued = 'false' + AND + appFamily.queued = 'false'$sAppDataQueued$sSelectType) UNION + ( + SELECT COUNT(DISTINCT appData.id) as count FROM appData, + appFamily, appVersion WHERE + appFamily.appId = appVersion.appId + AND + ( appData.versionId = appVersion.versionId ) AND appVersion.queued = 'false' AND - appFamily.queued = 'false'"; - - if($sQueued == "true" || $sQueued == "false") - $sQuery .= " AND appData.queued = '$sQueued'"; - + appFamily.queued = 'false'$sAppDataQueued$sSelectType)"; if($sType) - { - $sQuery .= " AND type = '?'"; - $hResult = query_parameters($sQuery, $sType); - } else + $hResult = query_parameters($sQuery, $sType, $sType); + else $hResult = query_parameters($sQuery); } if(!$hResult) return FALSE; - if(!$oRow = mysql_fetch_object($hResult)) - return FALSE; - - return $oRow->count; + for($iCount = 0; $oRow = mysql_fetch_object($hResult);) + $iCount += $oRow->count; + return $iCount; } function objectGetHeader($sType)