mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-24 02:38:50 +02:00
Cache the results for the parts of a category for KiCAD
This commit is contained in:
parent
b7af08503c
commit
ee69f9e576
1 changed files with 16 additions and 11 deletions
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||||
namespace App\Services\EDAIntegration;
|
namespace App\Services\EDAIntegration;
|
||||||
|
|
||||||
use App\Entity\Parts\Category;
|
use App\Entity\Parts\Category;
|
||||||
|
use App\Entity\Parts\Part;
|
||||||
use App\EntityListeners\TreeCacheInvalidationListener;
|
use App\EntityListeners\TreeCacheInvalidationListener;
|
||||||
use App\Services\Cache\ElementCacheTagGenerator;
|
use App\Services\Cache\ElementCacheTagGenerator;
|
||||||
use App\Services\Trees\NodesListBuilder;
|
use App\Services\Trees\NodesListBuilder;
|
||||||
|
@ -87,18 +88,22 @@ class KiCADHelper
|
||||||
*/
|
*/
|
||||||
public function getCategoryParts(Category $category): array
|
public function getCategoryParts(Category $category): array
|
||||||
{
|
{
|
||||||
$category_repo = $this->em->getRepository(Category::class);
|
return $this->kicadCache->get('kicad_category_parts_' . $category->getID(), function (ItemInterface $item) use ($category) {
|
||||||
$parts = $category_repo->getParts($category);
|
$item->tag([$this->tagGenerator->getElementTypeCacheTag(Category::class), $this->tagGenerator->getElementTypeCacheTag(Part::class)]);
|
||||||
|
|
||||||
$result = [];
|
$category_repo = $this->em->getRepository(Category::class);
|
||||||
foreach ($parts as $part) {
|
$parts = $category_repo->getParts($category);
|
||||||
$result[] = [
|
|
||||||
'id' => (string) $part->getId(),
|
|
||||||
'name' => $part->getName(),
|
|
||||||
'description' => $part->getDescription(),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result;
|
$result = [];
|
||||||
|
foreach ($parts as $part) {
|
||||||
|
$result[] = [
|
||||||
|
'id' => (string) $part->getId(),
|
||||||
|
'name' => $part->getName(),
|
||||||
|
'description' => $part->getDescription(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue