SimpleQuery: Cache count query result and use it in `hasResult()`

Does not affect views which do not run a count query. (e.g. dashlets)
Though, this is a quick win for all other views with which the user
interacts directly and gets the desired result quicker than before.

refs #3905
refs #3836
This commit is contained in:
Johannes Meyer 2019-09-26 12:50:51 +02:00
parent 908c408d3d
commit 8e5380220c
1 changed files with 9 additions and 1 deletions

View File

@ -36,6 +36,13 @@ class SimpleQuery implements QueryInterface, Queryable, Iterator
*/
protected $iteratorPosition;
/**
* The amount of rows previously calculated
*
* @var int
*/
protected $cachedCount;
/**
* The target you are going to query
*
@ -450,7 +457,7 @@ class SimpleQuery implements QueryInterface, Queryable, Iterator
*/
public function hasResult()
{
return $this->iteratorPosition !== null || $this->fetchRow() !== false;
return $this->cachedCount > 0 || $this->iteratorPosition !== null || $this->fetchRow() !== false;
}
/**
@ -647,6 +654,7 @@ class SimpleQuery implements QueryInterface, Queryable, Iterator
$query->limit(0, 0);
Benchmark::measure('Counting all results started');
$count = $this->ds->count($query);
$this->cachedCount = $count;
Benchmark::measure('Counting all results finished');
return $count;
}