Improve inline stats (#3865)
* deactivate timesheet stats if no filter was chosen (otherwise a full table scan would be triggered for each listing display) * hide duration stat if duration = 0 (timesheet, invoice, export)
This commit is contained in:
@@ -35,16 +35,22 @@ final class TimesheetResult
|
|||||||
public function getStatistic(): TimesheetResultStatistic
|
public function getStatistic(): TimesheetResultStatistic
|
||||||
{
|
{
|
||||||
if ($this->statisticCache === null) {
|
if ($this->statisticCache === null) {
|
||||||
|
$withDuration = $this->query->countFilter() > 0;
|
||||||
$qb = clone $this->queryBuilder;
|
$qb = clone $this->queryBuilder;
|
||||||
$qb
|
$qb
|
||||||
->resetDQLPart('select')
|
->resetDQLPart('select')
|
||||||
->resetDQLPart('orderBy')
|
->resetDQLPart('orderBy')
|
||||||
->select('COUNT(t.id) as counter')
|
->select('COUNT(t.id) as counter')
|
||||||
->addSelect('COALESCE(SUM(t.duration), 0) as duration');
|
;
|
||||||
|
|
||||||
|
if ($withDuration) {
|
||||||
|
$qb->addSelect('COALESCE(SUM(t.duration), 0) as duration');
|
||||||
|
}
|
||||||
|
|
||||||
$result = $qb->getQuery()->getArrayResult()[0];
|
$result = $qb->getQuery()->getArrayResult()[0];
|
||||||
|
$duration = $withDuration ? $result['duration'] : 0;
|
||||||
|
|
||||||
$this->statisticCache = new TimesheetResultStatistic($result['counter'], $result['duration']);
|
$this->statisticCache = new TimesheetResultStatistic($result['counter'], $duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->statisticCache;
|
return $this->statisticCache;
|
||||||
|
|||||||
@@ -41,7 +41,9 @@
|
|||||||
|
|
||||||
{% block status %}
|
{% block status %}
|
||||||
{% from "macros/status.html.twig" import status_duration, status_money %}
|
{% from "macros/status.html.twig" import status_duration, status_money %}
|
||||||
{{ status_duration(totalDuration|duration) }}
|
{% if totalDuration > 0 %}
|
||||||
|
{{ status_duration(totalDuration|duration) }}
|
||||||
|
{% endif %}
|
||||||
{% for totalCurrency, totalRate in totalRates %}
|
{% for totalCurrency, totalRate in totalRates %}
|
||||||
{{ status_money(totalRate|money(totalCurrency)) }}
|
{{ status_money(totalRate|money(totalCurrency)) }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|||||||
@@ -36,7 +36,9 @@
|
|||||||
|
|
||||||
{% block status %}
|
{% block status %}
|
||||||
{% from "macros/status.html.twig" import status_duration, status_money %}
|
{% from "macros/status.html.twig" import status_duration, status_money %}
|
||||||
{{ status_duration(totalDuration|duration) }}
|
{% if totalDuration > 0 %}
|
||||||
|
{{ status_duration(totalDuration|duration) }}
|
||||||
|
{% endif %}
|
||||||
{% for totalCurrency, totalRate in totalRates %}
|
{% for totalCurrency, totalRate in totalRates %}
|
||||||
{{ status_money(totalRate|money(totalCurrency)) }}
|
{{ status_money(totalRate|money(totalCurrency)) }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|||||||
@@ -59,8 +59,10 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block status %}
|
{% block status %}
|
||||||
{% from "macros/status.html.twig" import status_duration %}
|
{% if stats.duration > 0 %}
|
||||||
{{ status_duration(stats.duration|duration) }}
|
{% from "macros/status.html.twig" import status_duration %}
|
||||||
|
{{ status_duration(stats.duration|duration) }}
|
||||||
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block datatable_row_attr %}
|
{% block datatable_row_attr %}
|
||||||
|
|||||||
Reference in New Issue
Block a user