Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/MetaModels/MetaModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* @author Chris Raidler <c.raidler@rad-consulting.ch>
* @author David Molineus <david.molineus@netzmacht.de>
* @author Sven Baumann <baumann.sv@gmail.com>
* @author Ingolf Steinhardt <info@e-spin.de>
* @copyright 2012-2018 The MetaModels team.
* @license https://github.com/MetaModels/core/blob/master/LICENSE LGPL-3.0-or-later
* @filesource
Expand Down Expand Up @@ -76,6 +77,13 @@ class MetaModel implements IMetaModel
*/
protected $serviceContainer;

/**
* The cache existing ids.
*
* @var array
*/
private $existingIds = [];

/**
* Instantiate a MetaModel.
*
Expand Down Expand Up @@ -722,6 +730,11 @@ public function getIdsFromFilter($objFilter, $strSortBy = '', $intOffset = 0, $i
} elseif ('id' === $strSortBy) {
asort($arrFilteredIds);
} elseif (in_array($strSortBy, array('pid', 'tstamp', 'sorting'))) {
// Check existing ids.
if (array_intersect($arrFilteredIds, $this->existingIds) == $arrFilteredIds) {
return $arrFilteredIds;
}

// Sort by database values.
$arrFilteredIds = $this
->getDatabase()
Expand All @@ -736,6 +749,8 @@ public function getIdsFromFilter($objFilter, $strSortBy = '', $intOffset = 0, $i
)
->execute($arrFilteredIds)
->fetchEach('id');

$this->existingIds = array_merge($this->existingIds, $arrFilteredIds);
} elseif ($strSortBy == 'random') {
shuffle($arrFilteredIds);
}
Expand Down