From 4efd93defe105010e0a98d290f118d68f1b2d379 Mon Sep 17 00:00:00 2001 From: Romain Quetiez Date: Wed, 8 Jun 2011 14:42:51 +0000 Subject: [PATCH] Optimization: cache the Count of items in an object set SVN:trunk[1278] --- core/dbobjectset.class.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/core/dbobjectset.class.php b/core/dbobjectset.class.php index 24cbf7decd..81825a8c92 100644 --- a/core/dbobjectset.class.php +++ b/core/dbobjectset.class.php @@ -47,6 +47,7 @@ class DBObjectSet $this->m_iLimitCount = $iLimitCount; $this->m_iLimitStart = $iLimitStart; + $this->m_iCount = null; // null if unknown yet $this->m_bLoaded = false; // true when the filter has been used OR the set is built step by step (AddObject...) $this->m_aData = array(); // array of (row => array of (classalias) => object/null) $this->m_aId2Row = array(); // array of (pkey => index in m_aData) @@ -307,13 +308,17 @@ class DBObjectSet } else { - $sSQL = MetaModel::MakeSelectQuery($this->m_oFilter, $this->m_aOrderBy, $this->m_aArgs, null, 0, 0, true); - $resQuery = CMDBSource::Query($sSQL); - if (!$resQuery) return 0; - - $aRow = CMDBSource::FetchArray($resQuery); - CMDBSource::FreeResult($resQuery); - return $aRow['COUNT']; + if (is_null($this->m_iCount)) + { + $sSQL = MetaModel::MakeSelectQuery($this->m_oFilter, $this->m_aOrderBy, $this->m_aArgs, null, 0, 0, true); + $resQuery = CMDBSource::Query($sSQL); + if (!$resQuery) return 0; + + $aRow = CMDBSource::FetchArray($resQuery); + CMDBSource::FreeResult($resQuery); + $this->m_iCount = $aRow['COUNT']; + } + return $this->m_iCount; } }