mirror of
https://github.com/badlogic/heissepreise.git
synced 2024-06-16 05:34:21 +02:00
Fix blocking updateData when SKIP_FETCHING_STORE_DATA
is set in env.
This commit is contained in:
parent
dd2361515e
commit
5240ab2a46
15
analysis.js
15
analysis.js
|
@ -1,7 +1,9 @@
|
|||
const fs = require("fs");
|
||||
const fsAsync = require("fs").promises;
|
||||
const zlib = require("zlib");
|
||||
const stores = require("./stores");
|
||||
const { FILE } = require("dns");
|
||||
const { promisify } = require("util");
|
||||
|
||||
const STORE_KEYS = Object.keys(stores);
|
||||
exports.STORE_KEYS = STORE_KEYS;
|
||||
|
@ -25,6 +27,17 @@ function readJSON(file) {
|
|||
}
|
||||
exports.readJSON = readJSON;
|
||||
|
||||
async function readJSONAsync(file) {
|
||||
const gunzipAsync = promisify(zlib.gunzip);
|
||||
const brotliDecompressAsync = promisify(zlib.brotliDecompress);
|
||||
|
||||
let data = await fsAsync.readFile(file);
|
||||
if (file.endsWith(".gz")) data = await gunzipAsync(data);
|
||||
if (file.endsWith(".br")) data = await brotliDecompressAsync(data);
|
||||
return JSON.parse(data);
|
||||
}
|
||||
exports.readJSONAsync = readJSONAsync;
|
||||
|
||||
function writeJSON(file, data, fileCompressor = false, spacer = 2, compressData = false) {
|
||||
if (compressData) data = compress(data);
|
||||
data = JSON.stringify(data, null, spacer);
|
||||
|
@ -228,7 +241,7 @@ exports.updateData = async function (dataDir, done) {
|
|||
const rawDataFile = `${dataDir}/${store}-${today}.json`;
|
||||
let storeItems;
|
||||
if ("SKIP_FETCHING_STORE_DATA" in process.env && fs.existsSync(rawDataFile + "." + FILE_COMPRESSOR))
|
||||
storeItems = readJSON(rawDataFile + "." + FILE_COMPRESSOR);
|
||||
storeItems = await readJSONAsync(rawDataFile + "." + FILE_COMPRESSOR);
|
||||
else {
|
||||
storeItems = await stores[store].fetchData();
|
||||
writeJSON(rawDataFile, storeItems, FILE_COMPRESSOR);
|
||||
|
|
13
server.js
13
server.js
|
@ -37,9 +37,7 @@ function scheduleFunction(hour, minute, second, func) {
|
|||
}, delay);
|
||||
}
|
||||
|
||||
(async () => {
|
||||
const dataDir = "data";
|
||||
|
||||
function parseArguments() {
|
||||
const args = process.argv.slice(2);
|
||||
let port = process.env.PORT !== undefined && process.env.PORT != "" ? parseInt(process.env.PORT) : 3000;
|
||||
let liveReload = process.env.NODE_ENV === "development" || false;
|
||||
|
@ -62,6 +60,13 @@ function scheduleFunction(hour, minute, second, func) {
|
|||
}
|
||||
}
|
||||
|
||||
return { port, liveReload };
|
||||
}
|
||||
|
||||
(async () => {
|
||||
const dataDir = "data";
|
||||
const { port, liveReload } = parseArguments();
|
||||
|
||||
if (!fs.existsSync(dataDir)) {
|
||||
fs.mkdirSync(dataDir);
|
||||
}
|
||||
|
@ -70,7 +75,7 @@ function scheduleFunction(hour, minute, second, func) {
|
|||
bundle.deleteDirectory(outputDir);
|
||||
fs.mkdirSync(outputDir);
|
||||
fs.mkdirSync(outputDir + "/data");
|
||||
bundle.bundle("site", outputDir, liveReload);
|
||||
await bundle.bundle("site", outputDir, liveReload);
|
||||
|
||||
analysis.migrateCompression(dataDir, ".json", ".json.br");
|
||||
analysis.migrateCompression(dataDir, ".json.gz", ".json.br");
|
||||
|
|
|
@ -844,7 +844,7 @@ function showCharts(canvasDom, items, sum, sumStores, todayOnly, startDate, endD
|
|||
|
||||
if (sum && items.length > 0) {
|
||||
itemsToShow.push({
|
||||
name: "Preissumme Warenkorb",
|
||||
name: "Preissumme Gesamt",
|
||||
priceHistory: calculateOverallPriceChanges(items, todayOnly, startDate, endDate),
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user