added console logging to image script
continuous-integration/drone/push Build is failing Details

This commit is contained in:
Shahan Nedadahandeh 2022-06-01 19:12:54 -07:00
parent 6f6510a5ee
commit 5263c6880d
Signed by: snedadah
GPG Key ID: 8638C7F917385B01
2 changed files with 11 additions and 2 deletions

2
.gitignore vendored
View File

@ -28,4 +28,4 @@ yarn-error.log*
/public/events.ics
# Images should be optimized
/public/images
# /public/images

View File

@ -36,14 +36,19 @@ void optimizeImages();
export async function optimizeImages() {
const imagePaths = await getFilePathsInDirectory(SOURCE_DIRECTORY);
await fse.emptyDir(DESTINATION_DIRECTORY);
// await fse.emptyDir(DESTINATION_DIRECTORY);
// maximum number of workers is 4 in order to avoid running out of memory
const numberOfWorkers = Math.min(cpus().length, 4);
const imagePool = new ImagePool(numberOfWorkers);
let count = 0;
await Promise.all(
imagePaths.map(async (imagePath) => {
console.time(`on file ${imagePath}`);
count += 1;
const num = count;
console.time(`overall-timer${num}`);
const sourcePath = path.join(SOURCE_DIRECTORY, imagePath);
const destinationPath = path.join(DESTINATION_DIRECTORY, imagePath);
const fileExtension = imagePath.split(".").pop() ?? "";
@ -54,7 +59,10 @@ export async function optimizeImages() {
return;
}
console.time(`read-file-timer${num}`);
const rawImageFile = await fse.readFile(sourcePath);
console.timeEnd(`read-file-timer${num}`);
const ingestedImage = imagePool.ingestImage(rawImageFile);
const { width, height } = getImageDimensions(rawImageFile);
@ -84,6 +92,7 @@ export async function optimizeImages() {
const encodedImage = await ingestedImage.encodedWith[encoder];
await fse.outputFile(destinationPath, encodedImage.binary);
console.timeEnd(`overall-timer${num}`);
})
);