fix: only create furniture-line pages for lines with enough items

Add a LINE_PAGE_MIN_ITEMS threshold so small one-off lines collapse
onto the category page instead of creating hundreds of tiny pages.
This commit is contained in:
openhands committed 2026-08-22 11:32:13 +02:00
1 parent bb7ec3db02
commit b109ca6f32
1 file changed
+22 -3
+22 -3
View File
@@ -513,6 +513,11 @@ export async function organizeCatalogAll(): Promise<OrganizeCatalogResult> {
.replace(/^_+|_+$/g, "")
.slice(0, 40);
// Minimum number of items a furniture line must have before it gets its own
// dedicated catalog page. Lines below this threshold (one-off customs, etc.)
// collapse onto the category page so we don't create hundreds of tiny pages.
const LINE_PAGE_MIN_ITEMS = 3;
// Ensure a sub-page exists under the imported parent and return its id.
const ensureSubPage = async (
captionSave: string,
@@ -591,6 +596,20 @@ export async function organizeCatalogAll(): Promise<OrganizeCatalogResult> {
`)) as unknown as [Array<{ id: number }>, unknown];
const validPageIds = new Set(validPages.map((r) => Number(r.id)));
// Count items per furniture line so we only spin up a dedicated line page
// for lines that actually have enough items. Everything else falls back to
// the category page.
const lineCounts = new Map<string, number>();
for (const item of items) {
if (NO_CATALOG_KINDS.has(classifyCatalogItem(item))) continue;
const fl = resolveFurniline(item.item_name);
if (fl) lineCounts.set(fl, (lineCounts.get(fl) ?? 0) + 1);
}
const qualifyingLines = new Set<string>();
for (const [line, count] of lineCounts) {
if (count >= LINE_PAGE_MIN_ITEMS) qualifyingLines.add(line);
}
// Nitro presence (pets are purchasable without a furni .nitro bundle).
const { nitroDir } = await getFurniAssetDirs();
const nitroFiles = await readdir(nitroDir).catch(() => [] as string[]);
@@ -617,12 +636,12 @@ export async function organizeCatalogAll(): Promise<OrganizeCatalogResult> {
}
// Target page: the item's furniture line (e.g. "weebz", "habbox") when
// known, otherwise its auto-detected category. The line page is created
// if it does not exist yet.
// it qualifies for its own page, otherwise its auto-detected category.
// The line page is created if it does not exist yet.
let captionSave: string;
let caption: string;
const furniline = resolveFurniline(item.item_name);
if (furniline && slug(furniline)) {
if (furniline && slug(furniline) && qualifyingLines.has(furniline)) {
captionSave = `imp_line_${slug(furniline)}`;
caption = furniline;
} else {