0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00

perf(astro/assets): avoid downloading original image when using cache (#11904)

This commit is contained in:
Gabriel Pereira Woitechen 2024-09-04 10:32:03 -03:00 committed by GitHub
parent 5d7bc70fc3
commit ca54e3f819
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 9 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
perf(assets): avoid downloading original image when using cache

View file

@ -98,11 +98,11 @@ export async function generateImagesForPath(
env: AssetEnv,
queue: PQueue,
) {
const originalImageData = await loadImage(originalFilePath, env);
let originalImage: ImageData;
for (const [_, transform] of transformsAndPath.transforms) {
await queue
.add(async () => generateImage(originalImageData, transform.finalPath, transform.transform))
.add(async () => generateImage(transform.finalPath, transform.transform))
.catch((e) => {
throw e;
});
@ -128,13 +128,9 @@ export async function generateImagesForPath(
}
}
async function generateImage(
originalImage: ImageData,
filepath: string,
options: ImageTransform,
) {
async function generateImage(filepath: string, options: ImageTransform) {
const timeStart = performance.now();
const generationData = await generateImageInternal(originalImage, filepath, options);
const generationData = await generateImageInternal(filepath, options);
const timeEnd = performance.now();
const timeChange = getTimeStat(timeStart, timeEnd);
@ -151,7 +147,6 @@ export async function generateImagesForPath(
}
async function generateImageInternal(
originalImage: ImageData,
filepath: string,
options: ImageTransform,
): Promise<GenerationData> {
@ -207,6 +202,10 @@ export async function generateImagesForPath(
? (options.src as ImageMetadata).src
: (options.src as string);
if (!originalImage) {
originalImage = await loadImage(originalFilePath, env);
}
let resultData: Partial<ImageData> = {
data: undefined,
expires: originalImage.expires,