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:
Kevin Papst
2023-02-22 11:46:58 +01:00
committed by GitHub
parent 1bc1fadc56
commit cca3fa6b8a
4 changed files with 18 additions and 6 deletions

View File

@@ -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;