mirror of
https://github.com/samsonjs/spirit-tracker.git
synced 2026-03-25 09:25:51 +00:00
fix: to tudor
This commit is contained in:
parent
8b17d94516
commit
1e2bef8e6b
3 changed files with 79 additions and 1 deletions
|
|
@ -156,7 +156,6 @@ const PRODUCTS_QUERY = `
|
|||
$isStaffPick: Boolean,
|
||||
$pageCursor: String,
|
||||
$pageLimit: Int,
|
||||
$pointsMin: Int,
|
||||
$priceMin: Float,
|
||||
$priceMax: Float,
|
||||
$quantityMin: Float,
|
||||
|
|
|
|||
39
tools/dedupe_skulinks.js
Normal file
39
tools/dedupe_skulinks.js
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
const DB_DIR = path.join(__dirname, "data/db");
|
||||
const LINKS_FILE = path.join(__dirname, "data/sku_links.json");
|
||||
|
||||
// collect all valid SKUs from db files
|
||||
const validSkus = new Set();
|
||||
|
||||
for (const file of fs.readdirSync(DB_DIR)) {
|
||||
if (!file.endsWith(".json")) continue;
|
||||
const data = JSON.parse(fs.readFileSync(path.join(DB_DIR, file), "utf8"));
|
||||
if (!Array.isArray(data.items)) continue;
|
||||
for (const item of data.items) {
|
||||
if (item.sku) validSkus.add(String(item.sku));
|
||||
}
|
||||
}
|
||||
|
||||
// load links
|
||||
const linksData = JSON.parse(fs.readFileSync(LINKS_FILE, "utf8"));
|
||||
const originalCount = linksData.links.length;
|
||||
|
||||
// keep only links where BOTH skus exist
|
||||
linksData.links = linksData.links.filter(
|
||||
({ fromSku, toSku }) =>
|
||||
validSkus.has(String(fromSku)) && validSkus.has(String(toSku))
|
||||
);
|
||||
|
||||
// write back in place
|
||||
fs.writeFileSync(
|
||||
LINKS_FILE,
|
||||
JSON.stringify(linksData, null, 2) + "\n"
|
||||
);
|
||||
|
||||
console.log(
|
||||
`Pruned ${originalCount - linksData.links.length} invalid links`
|
||||
);
|
||||
40
tools/discover_bad_skus.js
Normal file
40
tools/discover_bad_skus.js
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
const DB_DIR = path.join(__dirname, "data/db");
|
||||
const LINKS_FILE = path.join(__dirname, "data/sku_links.json");
|
||||
|
||||
const includeKegNCork = process.argv.includes("--include-kegncork");
|
||||
const includeLinked = process.argv.includes("--include-linked");
|
||||
|
||||
// load linked SKUs
|
||||
const linkedSkus = new Set();
|
||||
if (!includeLinked && fs.existsSync(LINKS_FILE)) {
|
||||
const { links } = JSON.parse(fs.readFileSync(LINKS_FILE, "utf8"));
|
||||
for (const { fromSku, toSku } of links) {
|
||||
linkedSkus.add(String(fromSku));
|
||||
linkedSkus.add(String(toSku));
|
||||
}
|
||||
}
|
||||
|
||||
for (const file of fs.readdirSync(DB_DIR)) {
|
||||
if (!file.endsWith(".json")) continue;
|
||||
|
||||
if (!includeKegNCork && file.startsWith("kegncork__")) continue;
|
||||
|
||||
const data = JSON.parse(fs.readFileSync(path.join(DB_DIR, file), "utf8"));
|
||||
if (!Array.isArray(data.items)) continue;
|
||||
|
||||
for (const { sku, url } of data.items) {
|
||||
if (
|
||||
typeof sku === "string" &&
|
||||
sku.startsWith("u:") &&
|
||||
url &&
|
||||
(includeLinked || !linkedSkus.has(String(sku)))
|
||||
) {
|
||||
console.log(url);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue