From: Tim Otten Date: Fri, 29 Jun 2018 21:35:47 +0000 (-0700) Subject: (dev/core#217) CRM_Contact_Selector::getRows() - Use generator instead of DAO loop X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=fbef7ddcc6f871a6f0ce97758b81315bb2074126;p=civicrm-core.git (dev/core#217) CRM_Contact_Selector::getRows() - Use generator instead of DAO loop Currently, cached data is read from MySQL, so it's OK to treat `$result` as DAO. However, eventually, we'll cache in a different data-source, and (when dealing with multiple backend) it'll be easier to support a `Generator` rather than `CRM_Core_DAO`. See also: http://php.net/manual/en/language.generators.overview.php --- diff --git a/CRM/Contact/Selector.php b/CRM/Contact/Selector.php index 731f78c69d..c19789fa53 100644 --- a/CRM/Contact/Selector.php +++ b/CRM/Contact/Selector.php @@ -579,10 +579,10 @@ class CRM_Contact_Selector extends CRM_Core_Selector_Base implements CRM_Core_Se // note that the default action is basic if ($rowCount) { $cacheKey = $this->buildPrevNextCache($sort); - $result = $this->_query->getCachedContacts($cacheKey, $offset, $rowCount, $includeContactIds); + $resultSet = $this->_query->getCachedContacts($cacheKey, $offset, $rowCount, $includeContactIds)->fetchGenerator(); } else { - $result = $this->_query->searchQuery($offset, $rowCount, $sort, FALSE, $includeContactIds); + $resultSet = $this->_query->searchQuery($offset, $rowCount, $sort, FALSE, $includeContactIds)->fetchGenerator(); } // process the result of the query @@ -671,7 +671,7 @@ class CRM_Contact_Selector extends CRM_Core_Selector_Base implements CRM_Core_Se ); } - while ($result->fetch()) { + foreach ($resultSet as $result) { $row = array(); $this->_query->convertToPseudoNames($result); // the columns we are interested in