mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 09:35:49 +02:00
Use cached nodeslist when querying for subcategories.
This should increase performance for part lists.
This commit is contained in:
parent
31e89e2e36
commit
1e48c552dc
2 changed files with 12 additions and 14 deletions
|
@ -38,6 +38,8 @@ use App\Entity\Parts\Part;
|
||||||
use App\Entity\Parts\Storelocation;
|
use App\Entity\Parts\Storelocation;
|
||||||
use App\Entity\Parts\Supplier;
|
use App\Entity\Parts\Supplier;
|
||||||
use App\Services\EntityURLGenerator;
|
use App\Services\EntityURLGenerator;
|
||||||
|
use App\Services\ToolsTreeBuilder;
|
||||||
|
use App\Services\TreeBuilder;
|
||||||
use Doctrine\ORM\QueryBuilder;
|
use Doctrine\ORM\QueryBuilder;
|
||||||
use Omines\DataTablesBundle\Adapter\Doctrine\ORM\SearchCriteriaProvider;
|
use Omines\DataTablesBundle\Adapter\Doctrine\ORM\SearchCriteriaProvider;
|
||||||
use Omines\DataTablesBundle\Adapter\Doctrine\ORMAdapter;
|
use Omines\DataTablesBundle\Adapter\Doctrine\ORMAdapter;
|
||||||
|
@ -56,11 +58,13 @@ class PartsDataTable implements DataTableTypeInterface
|
||||||
*/
|
*/
|
||||||
protected $urlGenerator;
|
protected $urlGenerator;
|
||||||
protected $translator;
|
protected $translator;
|
||||||
|
protected $treeBuilder;
|
||||||
|
|
||||||
public function __construct(EntityURLGenerator $urlGenerator, TranslatorInterface $translator)
|
public function __construct(EntityURLGenerator $urlGenerator, TranslatorInterface $translator, TreeBuilder $treeBuilder)
|
||||||
{
|
{
|
||||||
$this->urlGenerator = $urlGenerator;
|
$this->urlGenerator = $urlGenerator;
|
||||||
$this->translator = $translator;
|
$this->translator = $translator;
|
||||||
|
$this->treeBuilder = $treeBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getQuery(QueryBuilder $builder)
|
protected function getQuery(QueryBuilder $builder)
|
||||||
|
@ -85,8 +89,7 @@ class PartsDataTable implements DataTableTypeInterface
|
||||||
|
|
||||||
if (isset($options['category'])) {
|
if (isset($options['category'])) {
|
||||||
$category = $options['category'];
|
$category = $options['category'];
|
||||||
$repo = $em->getRepository(Category::class);
|
$list = $this->treeBuilder->typeToNodesList(Category::class, $category);
|
||||||
$list = $repo->toNodesList($category);
|
|
||||||
$list[] = $category;
|
$list[] = $category;
|
||||||
|
|
||||||
$builder->andWhere('part.category IN (:cid)')->setParameter('cid', $list);
|
$builder->andWhere('part.category IN (:cid)')->setParameter('cid', $list);
|
||||||
|
@ -94,8 +97,7 @@ class PartsDataTable implements DataTableTypeInterface
|
||||||
|
|
||||||
if (isset($options['footprint'])) {
|
if (isset($options['footprint'])) {
|
||||||
$category = $options['footprint'];
|
$category = $options['footprint'];
|
||||||
$repo = $em->getRepository(Footprint::class);
|
$list = $this->treeBuilder->typeToNodesList(Footprint::class, $category);
|
||||||
$list = $repo->toNodesList($category);
|
|
||||||
$list[] = $category;
|
$list[] = $category;
|
||||||
|
|
||||||
$builder->andWhere('part.footprint IN (:cid)')->setParameter('cid', $list);
|
$builder->andWhere('part.footprint IN (:cid)')->setParameter('cid', $list);
|
||||||
|
@ -103,8 +105,7 @@ class PartsDataTable implements DataTableTypeInterface
|
||||||
|
|
||||||
if (isset($options['manufacturer'])) {
|
if (isset($options['manufacturer'])) {
|
||||||
$category = $options['manufacturer'];
|
$category = $options['manufacturer'];
|
||||||
$repo = $em->getRepository(Manufacturer::class);
|
$list = $this->treeBuilder->typeToNodesList(Manufacturer::class, $category);
|
||||||
$list = $repo->toNodesList($category);
|
|
||||||
$list[] = $category;
|
$list[] = $category;
|
||||||
|
|
||||||
$builder->andWhere('part.manufacturer IN (:cid)')->setParameter('cid', $list);
|
$builder->andWhere('part.manufacturer IN (:cid)')->setParameter('cid', $list);
|
||||||
|
@ -112,18 +113,16 @@ class PartsDataTable implements DataTableTypeInterface
|
||||||
|
|
||||||
if (isset($options['storelocation'])) {
|
if (isset($options['storelocation'])) {
|
||||||
$location = $options['storelocation'];
|
$location = $options['storelocation'];
|
||||||
$repo = $em->getRepository(Storelocation::class);
|
$list = $this->treeBuilder->typeToNodesList(Storelocation::class, $location);
|
||||||
$list = $repo->toNodesList($location);
|
|
||||||
$list[] = $location;
|
$list[] = $location;
|
||||||
|
|
||||||
$builder->andWhere('partLots.storage_location IN (:cid)')->setParameter('cid', $list);
|
$builder->andWhere('partLots.storage_location IN (:cid)')->setParameter('cid', $list);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($options['supplier'])) {
|
if (isset($options['supplier'])) {
|
||||||
$location = $options['supplier'];
|
$supplier = $options['supplier'];
|
||||||
$repo = $em->getRepository(Supplier::class);
|
$list = $this->treeBuilder->typeToNodesList(Supplier::class, $supplier);
|
||||||
$list = $repo->toNodesList($location);
|
$list[] = $supplier;
|
||||||
$list[] = $location;
|
|
||||||
|
|
||||||
$builder->andWhere('orderdetails.supplier IN (:cid)')->setParameter('cid', $list);
|
$builder->andWhere('orderdetails.supplier IN (:cid)')->setParameter('cid', $list);
|
||||||
}
|
}
|
||||||
|
|
|
@ -170,7 +170,6 @@ class TreeBuilder
|
||||||
* @param string $class_name The class name of the entity you want to retrieve.
|
* @param string $class_name The class name of the entity you want to retrieve.
|
||||||
* @param StructuralDBElement|null $parent This entity will be used as root element. Set to null, to use global root
|
* @param StructuralDBElement|null $parent This entity will be used as root element. Set to null, to use global root
|
||||||
* @return StructuralDBElement[] A flattened list containing the tree elements.
|
* @return StructuralDBElement[] A flattened list containing the tree elements.
|
||||||
* @throws \Psr\Cache\InvalidArgumentException
|
|
||||||
*/
|
*/
|
||||||
public function typeToNodesList(string $class_name, ?StructuralDBElement $parent = null): array
|
public function typeToNodesList(string $class_name, ?StructuralDBElement $parent = null): array
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue