bep40 commited on
Commit
edafc28
·
verified ·
1 Parent(s): 20254d7

Fix modal: zalo-sync products (newest from dataset) always prepend on top, not deduped against base catalog

Browse files
Files changed (1) hide show
  1. src/vaix-rag.js +19 -7
src/vaix-rag.js CHANGED
@@ -1128,7 +1128,7 @@ async function load() {
1128
  specs: (p.specs && typeof p.specs === "object") ? p.specs : {},
1129
  video: p.vid || "", image: p.i || p.image || "",
1130
  images: Array.isArray(p.imgs) ? p.imgs : (Array.isArray(p.g) ? p.g : []), link: p.l || "",
1131
- _addedBy: "products_url_added"
1132
  }));
1133
  // Dedup added products against base catalog AND against each other
1134
  // (by sku, slug, link, or normalized name) so a URL added twice never
@@ -1144,9 +1144,17 @@ async function load() {
1144
  const sl = String(p.slug || "").toLowerCase();
1145
  const lk = String(p.link || "").toLowerCase();
1146
  const nm = String(p.title_clean || p.name || "").toLowerCase().replace(/\s+/g, " ").trim();
1147
- // Collision with a base catalog product (same sku or slug) → drop.
1148
- if (sk && baseSkus.has(sk)) return false;
1149
- if (sl && baseSlugs.has(sl)) return false;
 
 
 
 
 
 
 
 
1150
  // Two URL-added records can share a name but have different SKUs
1151
  // (e.g. Hitachi BD-1054HVOW vs 357869). Keep the FIRST record for
1152
  // that name — file order puts the record with a link first.
@@ -1193,10 +1201,16 @@ async function load() {
1193
  specs: (p.specs && typeof p.specs === "object") ? p.specs : {},
1194
  video: p.vid || "", image: p.i || p.image || "",
1195
  images: Array.isArray(p.imgs) ? p.imgs : (Array.isArray(p.g) ? p.g : []), link: p.l || "",
1196
- _addedBy: "zalo-products-all-autosync"
1197
  }));
1198
  const baseSkus2 = new Set(allProducts.map((p) => String(p.sku).toLowerCase()).filter(Boolean));
1199
  const baseSlugs2 = new Set(allProducts.map((p) => String(p.slug || "").toLowerCase()).filter(Boolean));
 
 
 
 
 
 
1200
  const seenKeys2 = new Set();
1201
  const seenNames2 = new Set();
1202
  const uniqueLocal = localAdded.filter((p) => {
@@ -1204,8 +1218,6 @@ async function load() {
1204
  const sl = String(p.slug || "").toLowerCase();
1205
  const lk = String(p.link || "").toLowerCase();
1206
  const nm = String(p.title_clean || p.name || "").toLowerCase().replace(/\s+/g, " ").trim();
1207
- if (sk && baseSkus2.has(sk)) return false;
1208
- if (sl && baseSlugs2.has(sl)) return false;
1209
  if (nm && seenNames2.has(nm)) return false;
1210
  if (nm) seenNames2.add(nm);
1211
  let key = "";
 
1128
  specs: (p.specs && typeof p.specs === "object") ? p.specs : {},
1129
  video: p.vid || "", image: p.i || p.image || "",
1130
  images: Array.isArray(p.imgs) ? p.imgs : (Array.isArray(p.g) ? p.g : []), link: p.l || "",
1131
+ _source: p._source || "", _addedBy: "products_url_added"
1132
  }));
1133
  // Dedup added products against base catalog AND against each other
1134
  // (by sku, slug, link, or normalized name) so a URL added twice never
 
1144
  const sl = String(p.slug || "").toLowerCase();
1145
  const lk = String(p.link || "").toLowerCase();
1146
  const nm = String(p.title_clean || p.name || "").toLowerCase().replace(/\s+/g, " ").trim();
1147
+ // Zalo-sync rows (written by auto_sync_worker with _source
1148
+ // "zalo-products-all-autosync") carry the freshest dataset image +
1149
+ // newest _added_at they must NOT be dropped just because the base
1150
+ // catalog already has the same SKU. Only dedup them against other
1151
+ // rows in this same batch. Manual URL-added rows keep the old
1152
+ // collision behavior (drop if base already has the sku/slug).
1153
+ const isZaloSync = !!(p._source === "zalo-products-all-autosync" || p._addedBy === "zalo-products-all-autosync");
1154
+ if (!isZaloSync) {
1155
+ if (sk && baseSkus.has(sk)) return false;
1156
+ if (sl && baseSlugs.has(sl)) return false;
1157
+ }
1158
  // Two URL-added records can share a name but have different SKUs
1159
  // (e.g. Hitachi BD-1054HVOW vs 357869). Keep the FIRST record for
1160
  // that name — file order puts the record with a link first.
 
1201
  specs: (p.specs && typeof p.specs === "object") ? p.specs : {},
1202
  video: p.vid || "", image: p.i || p.image || "",
1203
  images: Array.isArray(p.imgs) ? p.imgs : (Array.isArray(p.g) ? p.g : []), link: p.l || "",
1204
+ _source: p._source || "", _addedBy: "zalo-products-all-autosync"
1205
  }));
1206
  const baseSkus2 = new Set(allProducts.map((p) => String(p.sku).toLowerCase()).filter(Boolean));
1207
  const baseSlugs2 = new Set(allProducts.map((p) => String(p.slug || "").toLowerCase()).filter(Boolean));
1208
+ // IMPORTANT: do NOT dedup zalo-sync products against the base catalog.
1209
+ // The base catalog (products_index.json, 11k rows) already contains
1210
+ // many of these SKUs (MH700GT, EVF015M, ...) with STALE/empty images
1211
+ // and OLD positions. The zalo-sync rows carry the fresh dataset image
1212
+ // + newest _added_at, so they must always be prepended on top of the
1213
+ // modal list. We only dedup against OTHER rows in this same batch.
1214
  const seenKeys2 = new Set();
1215
  const seenNames2 = new Set();
1216
  const uniqueLocal = localAdded.filter((p) => {
 
1218
  const sl = String(p.slug || "").toLowerCase();
1219
  const lk = String(p.link || "").toLowerCase();
1220
  const nm = String(p.title_clean || p.name || "").toLowerCase().replace(/\s+/g, " ").trim();
 
 
1221
  if (nm && seenNames2.has(nm)) return false;
1222
  if (nm) seenNames2.add(nm);
1223
  let key = "";