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:
parent
908c408d3d
commit
8e5380220c
|
@ -36,6 +36,13 @@ class SimpleQuery implements QueryInterface, Queryable, Iterator
|
||||||
*/
|
*/
|
||||||
protected $iteratorPosition;
|
protected $iteratorPosition;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The amount of rows previously calculated
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
protected $cachedCount;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The target you are going to query
|
* The target you are going to query
|
||||||
*
|
*
|
||||||
|
@ -450,7 +457,7 @@ class SimpleQuery implements QueryInterface, Queryable, Iterator
|
||||||
*/
|
*/
|
||||||
public function hasResult()
|
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);
|
$query->limit(0, 0);
|
||||||
Benchmark::measure('Counting all results started');
|
Benchmark::measure('Counting all results started');
|
||||||
$count = $this->ds->count($query);
|
$count = $this->ds->count($query);
|
||||||
|
$this->cachedCount = $count;
|
||||||
Benchmark::measure('Counting all results finished');
|
Benchmark::measure('Counting all results finished');
|
||||||
return $count;
|
return $count;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue