From cca3fa6b8ae3f7659eb815cb106c27de00894ca2 Mon Sep 17 00:00:00 2001 From: Kevin Papst Date: Wed, 22 Feb 2023 11:46:58 +0100 Subject: [PATCH] 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) --- src/Repository/Result/TimesheetResult.php | 10 ++++++++-- templates/export/index.html.twig | 4 +++- templates/invoice/index.html.twig | 4 +++- templates/timesheet/index.html.twig | 6 ++++-- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/Repository/Result/TimesheetResult.php b/src/Repository/Result/TimesheetResult.php index de5f1bc2..88c13134 100644 --- a/src/Repository/Result/TimesheetResult.php +++ b/src/Repository/Result/TimesheetResult.php @@ -35,16 +35,22 @@ final class TimesheetResult public function getStatistic(): TimesheetResultStatistic { if ($this->statisticCache === null) { + $withDuration = $this->query->countFilter() > 0; $qb = clone $this->queryBuilder; $qb ->resetDQLPart('select') ->resetDQLPart('orderBy') ->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]; + $duration = $withDuration ? $result['duration'] : 0; - $this->statisticCache = new TimesheetResultStatistic($result['counter'], $result['duration']); + $this->statisticCache = new TimesheetResultStatistic($result['counter'], $duration); } return $this->statisticCache; diff --git a/templates/export/index.html.twig b/templates/export/index.html.twig index e1472917..fa8888e6 100644 --- a/templates/export/index.html.twig +++ b/templates/export/index.html.twig @@ -41,7 +41,9 @@ {% block status %} {% 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 %} {{ status_money(totalRate|money(totalCurrency)) }} {% endfor %} diff --git a/templates/invoice/index.html.twig b/templates/invoice/index.html.twig index 1250157d..be765625 100644 --- a/templates/invoice/index.html.twig +++ b/templates/invoice/index.html.twig @@ -36,7 +36,9 @@ {% block status %} {% 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 %} {{ status_money(totalRate|money(totalCurrency)) }} {% endfor %} diff --git a/templates/timesheet/index.html.twig b/templates/timesheet/index.html.twig index 76dc242d..1f28bd54 100644 --- a/templates/timesheet/index.html.twig +++ b/templates/timesheet/index.html.twig @@ -59,8 +59,10 @@ {% endblock %} {% block status %} - {% from "macros/status.html.twig" import status_duration %} - {{ status_duration(stats.duration|duration) }} + {% if stats.duration > 0 %} + {% from "macros/status.html.twig" import status_duration %} + {{ status_duration(stats.duration|duration) }} + {% endif %} {% endblock %} {% block datatable_row_attr %}