// and contain the search criteria (parameters)
// note that the default action is basic
if ($rowCount) {
+ /** @var CRM_Core_PrevNextCache_Interface $prevNext */
+ $prevNext = Civi::service('prevnext');
$cacheKey = $this->buildPrevNextCache($sort);
- $resultSet = $this->_query->getCachedContacts($cacheKey, $offset, $rowCount, $includeContactIds)->fetchGenerator();
+ $cids = $prevNext->fetch($cacheKey, $offset, $rowCount);
+ $resultSet = empty($cids) ? [] : $this->_query->getCachedContacts($cids, $includeContactIds)->fetchGenerator();
}
else {
$resultSet = $this->_query->searchQuery($offset, $rowCount, $sort, FALSE, $includeContactIds)->fetchGenerator();
// the other alternative of running the FULL query will just be incredibly inefficient
// and slow things down way too much on large data sets / complex queries
- $selectSQL = "SELECT DISTINCT 'civicrm_contact', contact_a.id, contact_a.id, '$cacheKey', contact_a.sort_name";
+ $selectSQL = "SELECT DISTINCT '$cacheKey', contact_a.id, contact_a.sort_name";
$sql = str_replace(array("SELECT contact_a.id as contact_id", "SELECT contact_a.id as id"), $selectSQL, $sql);
try {