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.
This commit is contained in:
parent
77348a9323
commit
0e28646b62
|
|
@ -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<boolean> =>
|
||||
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<Folders> => {
|
||||
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
|
||||
|
|
|
|||
Loading…
Reference in New Issue