Skip to content

Commit

Permalink
perf(astro/assets): avoid downloading original image when using cache
Browse files Browse the repository at this point in the history
  • Loading branch information
wtchnm committed Sep 2, 2024
1 parent cd54210 commit f87148e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/purple-ears-sneeze.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

perf(assets): avoid downloading original image when using cache
14 changes: 4 additions & 10 deletions packages/astro/src/assets/build/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,9 @@ export async function generateImagesForPath(
env: AssetEnv,
queue: PQueue,
) {
const originalImageData = await loadImage(originalFilePath, env);

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;
});
Expand All @@ -128,13 +126,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);
Expand All @@ -151,7 +145,6 @@ export async function generateImagesForPath(
}

async function generateImageInternal(
originalImage: ImageData,
filepath: string,
options: ImageTransform,
): Promise<GenerationData> {
Expand Down Expand Up @@ -207,6 +200,7 @@ export async function generateImagesForPath(
? (options.src as ImageMetadata).src
: (options.src as string);

const originalImage = await loadImage(originalFilePath, env);
let resultData: Partial<ImageData> = {
data: undefined,
expires: originalImage.expires,
Expand Down

0 comments on commit f87148e

Please sign in to comment.