From ea64f5a301e155dfe88392e3cdf5e535275fd922 Mon Sep 17 00:00:00 2001 From: Lukas Runge Date: Wed, 9 Sep 2026 18:04:43 +0200 Subject: [PATCH 1/2] Fix stale KiCad category listing after EDA settings change The KiCad category parts listing is cached and only invalidated by entity changes (parts, categories, footprints). Settings that change the exported fields (datasheet as PDF, default parameter/orderdetail visibility) did not invalidate it, so KiCad kept receiving the old listing until any part was edited. Include a fingerprint of these settings in the cache key, so a settings change results in a fresh listing. Co-Authored-By: Claude Fable 5.1 --- src/Services/EDA/KiCadHelper.php | 18 ++++++++++++- tests/Services/EDA/KiCadHelperTest.php | 35 ++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/src/Services/EDA/KiCadHelper.php b/src/Services/EDA/KiCadHelper.php index 85159c51d..16bdf3695 100644 --- a/src/Services/EDA/KiCadHelper.php +++ b/src/Services/EDA/KiCadHelper.php @@ -145,7 +145,10 @@ public function getCategories(): array */ public function getCategoryParts(?Category $category): array { - $cacheKey = 'kicad_category_parts_'.($category?->getID() ?? 0) . '_' . $this->category_depth; + // Settings fingerprint keeps cached responses from surviving settings changes + // (tag-based invalidation only fires on part/category/footprint edits) + $cacheKey = 'kicad_category_parts_'.($category?->getID() ?? 0) . '_' . $this->category_depth + . '_' . $this->edaSettingsFingerprint(); return $this->kicadCache->get($cacheKey, function (ItemInterface $item) use ($category) { $item->tag([ @@ -355,6 +358,19 @@ public function getKiCADPart(Part $part): array return $result; } + /** + * Fingerprint of every setting that changes the content of a serialized part. + */ + private function edaSettingsFingerprint(): string + { + return md5(json_encode([ + $this->datasheetAsPdf, + $this->kiCadEDASettings->defaultOrderdetailsVisibility, + $this->kiCadEDASettings->defaultParameterVisibility, + $this->kiCadEDASettings->defaultParameterSymbolVisibility, + ], JSON_THROW_ON_ERROR)); + } + /** * Determine if the given part should be visible for the EDA. * @param Category $category diff --git a/tests/Services/EDA/KiCadHelperTest.php b/tests/Services/EDA/KiCadHelperTest.php index b043d5980..1d094d6e8 100644 --- a/tests/Services/EDA/KiCadHelperTest.php +++ b/tests/Services/EDA/KiCadHelperTest.php @@ -33,6 +33,7 @@ use App\Entity\Parts\Supplier; use App\Entity\PriceInformations\Orderdetail; use App\Services\EDA\KiCadHelper; +use App\Settings\MiscSettings\KiCadEDASettings; use Doctrine\ORM\EntityManagerInterface; use PHPUnit\Framework\Attributes\Group; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; @@ -654,4 +655,38 @@ public function testCategoryPartsListingContainsFields(): void self::assertArrayHasKey('symbolIdStr', $part); } } + + /** + * The category listing is cached and only invalidated by entity changes. + * Changing a setting that affects the exported fields must not serve a stale listing. + */ + public function testCategoryPartsCacheIsInvalidatedBySettingsChange(): void + { + /** @var KiCadEDASettings $settings */ + $settings = self::getContainer()->get(KiCadEDASettings::class); + $category = $this->em->find(Category::class, 1); + + $part = new Part(); + $part->setName('Part for cache test'); + $part->setCategory($category); + $param = new PartParameter(); + $param->setName('CacheTestParam'); + $param->setValueText('42'); + $param->setEdaVisibility(null); + $part->addParameter($param); + $this->em->persist($part); + $this->em->flush(); + + $findFields = fn(array $listing): array => array_values(array_filter($listing, fn($p) => (int) $p['id'] === $part->getId()))[0]['fields']; + + $settings->defaultParameterVisibility = false; + $before = $findFields($this->helper->getCategoryParts($category)); + self::assertArrayNotHasKey('CacheTestParam', $before); + + // No entity changed, only the setting: the cached listing must not be reused + $settings->defaultParameterVisibility = true; + $after = $findFields($this->helper->getCategoryParts($category)); + self::assertArrayHasKey('CacheTestParam', $after); + self::assertSame('42', $after['CacheTestParam']['value']); + } } From b4dea502339550f4d48ebfd8b1ec9c98e65bed7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Thu, 17 Sep 2026 23:12:57 +0200 Subject: [PATCH 2/2] Use xxh3 hash instead of md5 --- src/Services/EDA/KiCadHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Services/EDA/KiCadHelper.php b/src/Services/EDA/KiCadHelper.php index 16bdf3695..62acacdd5 100644 --- a/src/Services/EDA/KiCadHelper.php +++ b/src/Services/EDA/KiCadHelper.php @@ -363,7 +363,7 @@ public function getKiCADPart(Part $part): array */ private function edaSettingsFingerprint(): string { - return md5(json_encode([ + return hash("xxh3", json_encode([ $this->datasheetAsPdf, $this->kiCadEDASettings->defaultOrderdetailsVisibility, $this->kiCadEDASettings->defaultParameterVisibility,