From 0e28646b628677e418f1caaa26029b9d8ba30eaf Mon Sep 17 00:00:00 2001 From: Stefan Forstenlechner Date: Thu, 15 Aug 2024 23:33:40 +0200 Subject: [PATCH] Remove image check when loading number of files Checking if an image is processable when loading the directory slowed down the initial loading of the directories significantly. 7ms vs 180ms in a small test with about 400 images. User should not have any other files in these folders. Other methods still contain sanity checks. --- picture-gallery-server/src/fsExtension.ts | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/picture-gallery-server/src/fsExtension.ts b/picture-gallery-server/src/fsExtension.ts index 042c972..69f6fd0 100644 --- a/picture-gallery-server/src/fsExtension.ts +++ b/picture-gallery-server/src/fsExtension.ts @@ -1,34 +1,14 @@ import fs from "fs"; import * as path from "path"; -import sharp from "sharp"; import { Folders } from "./models"; import { publicPath, thumbnailPath } from "./paths"; -import { consoleLogger } from "./logging"; - -const isImageProcessable = async (filePath: string): Promise => - sharp(filePath) - .metadata() - .then(() => true) - .catch((err) => { - consoleLogger.error( - `Reading metadata from ${filePath} produced the following error: ${err.message}`, - ); - return false; - }); export const walk = async (dirPath: string): Promise => { const dirEnts = fs.readdirSync(path.posix.join(publicPath, dirPath), { withFileTypes: true, }); - const numberOfFiles = ( - await Promise.all( - dirEnts - .filter((f) => f.isFile()) - .map((f) => path.posix.join(publicPath, dirPath, f.name)) - .map(isImageProcessable), - ) - ).filter((a) => a).length; + const numberOfFiles = dirEnts.filter((f) => f.isFile()).length; const children = await Promise.all( dirEnts