Skip to content

Commit 79a1548

Browse files
committed
PR #1241 from zonky2
2 parents 5ca98e9 + de6d298 commit 79a1548

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/MetaModels/MetaModel.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* @author Chris Raidler <c.raidler@rad-consulting.ch>
2222
* @author David Molineus <david.molineus@netzmacht.de>
2323
* @author Sven Baumann <baumann.sv@gmail.com>
24+
* @author Ingolf Steinhardt <info@e-spin.de>
2425
* @copyright 2012-2018 The MetaModels team.
2526
* @license https://github.com/MetaModels/core/blob/master/LICENSE LGPL-3.0-or-later
2627
* @filesource
@@ -76,6 +77,13 @@ class MetaModel implements IMetaModel
7677
*/
7778
protected $serviceContainer;
7879

80+
/**
81+
* The cache existing ids.
82+
*
83+
* @var array
84+
*/
85+
private $existingIds = [];
86+
7987
/**
8088
* Instantiate a MetaModel.
8189
*
@@ -722,6 +730,11 @@ public function getIdsFromFilter($objFilter, $strSortBy = '', $intOffset = 0, $i
722730
} elseif ('id' === $strSortBy) {
723731
asort($arrFilteredIds);
724732
} elseif (in_array($strSortBy, array('pid', 'tstamp', 'sorting'))) {
733+
// Check existing ids.
734+
if (array_intersect($arrFilteredIds, $this->existingIds) == $arrFilteredIds) {
735+
return $arrFilteredIds;
736+
}
737+
725738
// Sort by database values.
726739
$arrFilteredIds = $this
727740
->getDatabase()
@@ -736,6 +749,8 @@ public function getIdsFromFilter($objFilter, $strSortBy = '', $intOffset = 0, $i
736749
)
737750
->execute($arrFilteredIds)
738751
->fetchEach('id');
752+
753+
$this->existingIds = array_merge($this->existingIds, $arrFilteredIds);
739754
} elseif ($strSortBy == 'random') {
740755
shuffle($arrFilteredIds);
741756
}

0 commit comments

Comments
 (0)