Fix double query execution

Our monitoring list views call SimpleQuery::hasResult() first in
order to determine whether there are results to display. This calls
fetchRow() which executes the underlying query the first time. If there
are resulsts, the query is iterated which executes the query again.
With this patch, SimpleQuery::hasResult() makes use of the inner
iterator instead of calling fetchRow(). The query is now executed only
once.
This commit is contained in:
Eric Lippmann 2019-06-26 09:57:19 +02:00
parent 4dcea91775
commit b20291a606
1 changed files with 11 additions and 1 deletions

View File

@ -450,7 +450,17 @@ class SimpleQuery implements QueryInterface, Queryable, Iterator
*/
public function hasResult()
{
return $this->iteratorPosition !== null || $this->fetchRow() !== false;
if ($this->iteratorPosition !== null) {
return true;
}
$hasResult = false;
foreach ($this as $row) {
$hasResult = true;
break;
}
return $hasResult;
}
/**