mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-31 01:34:09 +02:00
Use GROUPBY instead of DISTINCT and subqueries when counting
This commit is contained in:
parent
f86d3e7636
commit
77f5bc3932
@ -72,6 +72,12 @@ class DbQuery extends SimpleQuery
|
|||||||
parent::init();
|
parent::init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setUseSubqueryCount($useSubqueryCount = true)
|
||||||
|
{
|
||||||
|
$this->useSubqueryCount = $useSubqueryCount;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function where($condition, $value = null)
|
public function where($condition, $value = null)
|
||||||
{
|
{
|
||||||
// $this->count = $this->select = null;
|
// $this->count = $this->select = null;
|
||||||
@ -259,7 +265,7 @@ class DbQuery extends SimpleQuery
|
|||||||
*/
|
*/
|
||||||
public function getCountQuery()
|
public function getCountQuery()
|
||||||
{
|
{
|
||||||
// TODO: there may be situations where we should clone the "select"
|
// TODO: there may be situations where we should clone the "select"
|
||||||
$count = $this->dbSelect();
|
$count = $this->dbSelect();
|
||||||
|
|
||||||
$this->applyFilterSql($count);
|
$this->applyFilterSql($count);
|
||||||
|
@ -69,11 +69,13 @@ class PivotTable
|
|||||||
protected function prepareQueries()
|
protected function prepareQueries()
|
||||||
{
|
{
|
||||||
$this->xAxisQuery = clone $this->baseQuery;
|
$this->xAxisQuery = clone $this->baseQuery;
|
||||||
$this->xAxisQuery->distinct();
|
$this->xAxisQuery->group($this->xAxisColumn);
|
||||||
$this->xAxisQuery->columns(array($this->xAxisColumn));
|
$this->xAxisQuery->columns(array($this->xAxisColumn));
|
||||||
|
$this->xAxisQuery->setUseSubqueryCount();
|
||||||
$this->yAxisQuery = clone $this->baseQuery;
|
$this->yAxisQuery = clone $this->baseQuery;
|
||||||
$this->yAxisQuery->distinct();
|
$this->yAxisQuery->group($this->yAxisColumn);
|
||||||
$this->yAxisQuery->columns(array($this->yAxisColumn));
|
$this->yAxisQuery->columns(array($this->yAxisColumn));
|
||||||
|
$this->yAxisQuery->setUseSubqueryCount();
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@ -85,24 +87,14 @@ class PivotTable
|
|||||||
*/
|
*/
|
||||||
protected function adjustSorting()
|
protected function adjustSorting()
|
||||||
{
|
{
|
||||||
$currentOrderColumns = $this->baseQuery->getOrder();
|
if (false === $this->xAxisQuery->hasOrder($this->xAxisColumn)) {
|
||||||
$xAxisOrderColumns = array(array($this->baseQuery->getMappedField($this->xAxisColumn), SimpleQuery::SORT_ASC));
|
$this->xAxisQuery->order($this->xAxisColumn, 'ASC');
|
||||||
$yAxisOrderColumns = array(array($this->baseQuery->getMappedField($this->yAxisColumn), SimpleQuery::SORT_ASC));
|
|
||||||
|
|
||||||
foreach ($currentOrderColumns as $orderInfo) {
|
|
||||||
if ($orderInfo[0] === $xAxisOrderColumns[0][0]) {
|
|
||||||
$xAxisOrderColumns[0] = $orderInfo;
|
|
||||||
} elseif ($orderInfo[0] === $yAxisOrderColumns[0][0]) {
|
|
||||||
$yAxisOrderColumns[0] = $orderInfo;
|
|
||||||
} else {
|
|
||||||
$xAxisOrderColumns[] = $orderInfo;
|
|
||||||
$yAxisOrderColumns[] = $orderInfo;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
//TODO: simplify this whole function. No need to care about mapping
|
|
||||||
// foreach ($xAxisOrderColumns as
|
if (false === $this->yAxisQuery->hasOrder($this->yAxisColumn)) {
|
||||||
// $this->xAxisQuery->setOrder($xAxisOrderColumns);
|
$this->yAxisQuery->order($this->yAxisColumn, 'ASC');
|
||||||
// $this->yAxisQuery->setOrder($yAxisOrderColumns);
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user