[object Object]

← back to Museumwallpaper

fix /api/facets: compute aesthetic counts without aesthetic filter so all chips show real reachable counts (TK-10119)

7f65cf64367ba6d0956f087dfee5c4fcf38adffe · 2026-08-03 04:08:35 -0700 · Steve

Files touched

Diff

commit 7f65cf64367ba6d0956f087dfee5c4fcf38adffe
Author: Steve <steve@designerwallcoverings.com>
Date:   Mon Aug 3 04:08:35 2026 -0700

    fix /api/facets: compute aesthetic counts without aesthetic filter so all chips show real reachable counts (TK-10119)
---
 server.js | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/server.js b/server.js
index 7136882..d3ad604 100644
--- a/server.js
+++ b/server.js
@@ -269,21 +269,21 @@ app.get('/api/sliders', (req, res) => {
 });
 
 app.get('/api/facets', (req, res) => {
-  // Counts MUST reflect the same filters as /api/products so chip labels match
-  // post-filter card counts (q, aesthetic). vendor filter is dropped upstream by
-  // api-vendor-redact middleware.
+  // Drill-down: aesthetic counts over the q-filtered list WITHOUT the aesthetic
+  // filter so all chips show reachable counts, not just the active rail. total
+  // and vendors use the fully-filtered set.
   const { q, aesthetic } = req.query;
-  let list = PRODUCTS_NICHE;
+  let listQ = PRODUCTS_NICHE;
   if (q) {
     const needle = String(q).toLowerCase();
-    list = list.filter(p => (p.title || '').toLowerCase().includes(needle) || (p.description || p.body_html || '').toLowerCase().includes(needle) || (p.product_type || '').toLowerCase().includes(needle) || (p.vendor || '').toLowerCase().includes(needle) || (p.sku || '').toLowerCase().includes(needle) || (p.tags || []).some(t => String(t).toLowerCase().includes(needle)));
+    listQ = listQ.filter(p => (p.title || '').toLowerCase().includes(needle) || (p.description || p.body_html || '').toLowerCase().includes(needle) || (p.product_type || '').toLowerCase().includes(needle) || (p.vendor || '').toLowerCase().includes(needle) || (p.sku || '').toLowerCase().includes(needle) || (p.tags || []).some(t => String(t).toLowerCase().includes(needle)));
   }
-  if (aesthetic && aesthetic !== 'all') list = list.filter(p => productInRail(p, aesthetic, RAIL_SYN));
-  const aesthetics = railFacets(list, SITE_RAILS, RAIL_SYN); const vendors = {};
-  for (const p of list) {
+  const listFull = (aesthetic && aesthetic !== 'all') ? listQ.filter(p => productInRail(p, aesthetic, RAIL_SYN)) : listQ;
+  const aesthetics = railFacets(listQ, SITE_RAILS, RAIL_SYN); const vendors = {};
+  for (const p of listFull) {
     vendors[p.vendor] = (vendors[p.vendor] || 0) + 1;
   }
-  res.json({ aesthetics, vendors, total: list.length });
+  res.json({ aesthetics, vendors, total: listFull.length });
 });
 
 app.get('/api/health', (req, res) => res.json({ status: 'ok', count: PRODUCTS_NICHE.length, dropped: DROPPED }));

← 2067145 museumwallpaper: adopt href-to-deeper-data storefront primit  ·  back to Museumwallpaper  ·  GA4: propagate site gtag to untagged pages (fleet coverage) d38b383 →