Skip to content

Commit

Permalink
Improve combined data compression
Browse files Browse the repository at this point in the history
  • Loading branch information
alistairjcbrown committed Nov 3, 2024
1 parent c8e5eff commit 5b27306
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
1 change: 0 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"main": "index.js",
"scripts": {
"test": "jest",
"format": "prettier \"./**/*.js(on)?\" --write && prettier \"./**/*.md\" --write --prose-wrap=always",
"format": "prettier \"./**/*.js(on)?\" --write && prettier \"./**/*.ts(x)?\" --write && prettier \"./**/*.md\" --write --prose-wrap=always",
"generate": "TZ=Europe/London node index.js",
"output:highlight-hydration-misses-for-review": "node ./scripts/highlight-hydration-misses-for-review.js",
"clear:cache": "rm -rf ./cache && git checkout ./cache",
Expand All @@ -25,7 +25,6 @@
"dotenv": "^16.4.5",
"ics": "^3.7.6",
"moviedb-promise": "^4.0.7",
"nanoid": "^3.3.7",
"playwright": "^1.48.1",
"replace-special-characters": "^1.2.7",
"slugify": "^1.6.6"
Expand Down
18 changes: 10 additions & 8 deletions scripts/generate-combined-data.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
const { writeFileSync } = require("node:fs");
const path = require("node:path");
const { nanoid } = require("nanoid");
const crypto = require("node:crypto");
const { compress, trimUndefinedRecursively } = require("compress-json");
const getSites = require("../common/get-sites");
const normalizeTitle = require("../common/normalize-title");
const { getMovieInfoAndCacheResults } = require("../common/get-movie-data");
const { parseMinsToMs } = require("../common/utils");

const getId = () => nanoid(8);
const getId = (value) =>
crypto.createHash("sha256").update(value).digest("hex").slice(0, 8);

const getCertification = ({ release_dates: { results } }) => {
const result = results.find(({ iso_3166_1: locale }) => locale === "GB");
Expand Down Expand Up @@ -69,11 +70,11 @@ const siteData = {
(async function () {
for (cinema in data) {
console.log(`[🎞️ Cinema: ${cinema}]`);
const venueId = getId();
const {
attributes: { name, url, address, geo },
shows,
} = data[cinema];
const venueId = getId(name);

siteData.venues[venueId] = {
id: venueId,
Expand Down Expand Up @@ -101,7 +102,7 @@ const siteData = {
}
}

const movieId = movieInfo ? movieInfo.id : getId();
const movieId = movieInfo ? movieInfo.id : getId(title);
if (!siteData.movies[movieId]) {
if (movieInfo) {
const directors = getDirectors(movieInfo);
Expand All @@ -115,7 +116,7 @@ const siteData = {
siteData.movies[movieId] = {
id: movieId,
title: movieInfo.title,
normalizedTitla: normalizeTitle(movieInfo.title),
normalizedTitle: normalizeTitle(movieInfo.title),
certification: getCertification(movieInfo),
overview: movieInfo.overview,
year: movieInfo.release_date.split("-")[0],
Expand All @@ -133,14 +134,15 @@ const siteData = {
siteData.movies[movieId] = {
id: movieId,
title: title,
normalizedTitle: normalizeTitle(title),
isUnmatched: true,
showings: {},
performances: [],
};
}
}

const showingId = getId();
const showingId = getId(`${venueId}-${title}`);
const movie = siteData.movies[movieId];

movie.showings[showingId] = {
Expand All @@ -165,9 +167,9 @@ const siteData = {

process.stdout.write(`Compressing data ... `);
try {
const dataFile = `./output/combined-data.json`;
const dataFile = `./site/public/combined-data.json`;
trimUndefinedRecursively(siteData);
const compressed = compress(siteData).toString();
const compressed = JSON.stringify(compress(siteData));
console.log(`✅ Compressed`);

writeFileSync(dataFile, compressed);
Expand Down

0 comments on commit 5b27306

Please sign in to comment.