(dev/core#217) CRM_Contact_Selector::getRows() - Use generator instead of DAO loop
authorTim Otten <totten@civicrm.org>
Fri, 29 Jun 2018 21:35:47 +0000 (14:35 -0700)
committerTim Otten <totten@civicrm.org>
Sat, 7 Jul 2018 02:43:46 +0000 (19:43 -0700)
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<Object>` rather than `CRM_Core_DAO`.

See also: http://php.net/manual/en/language.generators.overview.php

CRM/Contact/Selector.php

index 731f78c69d6eacdc41d6f5ae5059ddf6a7800154..c19789fa539c4fb0c053149f0af8ade4db6ea5a8 100644 (file)
@@ -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