fix(catalog): self-heal nav-crumb junk children in drill path

getCategoryWithParts returned persisted child categories without the
nav-crumb filter, so a node whose subgroups were polluted with "Portal"
(e.g. Hyundai BODY → only child "Portal") drilled to a dead junk node.
Drop nav-crumb children, delete them from the DB so the node re-fetches its
real subgroups, and also skip nav-crumbs when persisting freshly-fetched
subgroups. Real subgroups (illustration codes) and parts are reached as
before once the junk is gone.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-05 14:48:28 +03:00
parent 69251edc45
commit 1713616ba1

View File

@@ -738,6 +738,20 @@ export class CatalogService {
.from(categories)
.where(eq(categories.parentId, categoryId));
// Self-healing: drop nav-crumb junk children (e.g. "Portal"/eu.nissan.biz rows
// persisted by the old parser) and delete them so this node re-fetches the real
// subgroups instead of returning a junk-only child set.
const navCrumbChildren = children.filter((c) => this.isNavCrumbLink(c.linkPath));
if (navCrumbChildren.length > 0) {
await this.db.delete(categories).where(
inArray(
categories.id,
navCrumbChildren.map((c) => c.id),
),
);
children = children.filter((c) => !this.isNavCrumbLink(c.linkPath));
}
// Self-healing: if the linkPath is a leaf path but DB has children, those are
// stale records created by the previous case-insensitive bug. Delete and re-fetch.
if (children.length > 0 && linkPath && this.isLeafPath(linkPath)) {
@@ -774,6 +788,7 @@ export class CatalogService {
if (subGroups.length > 0) {
const seenNames = new Set<string>();
const unique = subGroups.filter((sg) => {
if (this.isNavCrumbLink(sg.linkPath)) return false;
if (seenNames.has(sg.name)) return false;
seenNames.add(sg.name);
return true;