performance tuning on timesheets (#874)

This commit is contained in:
Kevin Papst
2019-06-20 16:05:31 +02:00
committed by GitHub
parent bb8572a364
commit 9fbbaf9b88
11 changed files with 290 additions and 50 deletions

View File

@@ -0,0 +1,73 @@
<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Repository\Paginator;
use App\Repository\Loader\TimesheetLoader;
use Doctrine\ORM\Query;
use Doctrine\ORM\QueryBuilder;
use Pagerfanta\Adapter\AdapterInterface;
final class TimesheetPaginator implements AdapterInterface
{
/**
* @var QueryBuilder
*/
private $query;
/**
* @var int
*/
private $results = 0;
/**
* @var TimesheetLoader
*/
private $loader;
public function __construct(QueryBuilder $query, int $results)
{
$this->query = $query;
$this->results = $results;
$this->loader = new TimesheetLoader($query->getEntityManager());
}
/**
* {@inheritdoc}
*/
public function getNbResults()
{
return $this->results;
}
private function getResults(Query $query)
{
$results = $query->execute();
$this->loader->loadResults($results);
return $results;
}
/**
* {@inheritdoc}
*/
public function getSlice($offset, $length)
{
$query = $this->query
->getQuery()
->setFirstResult($offset)
->setMaxResults($length);
return $this->getResults($query);
}
public function getAll()
{
return $this->getResults($this->query->getQuery());
}
}