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:
parent
5d7bc70fc3
commit
ca54e3f819
2 changed files with 13 additions and 9 deletions
5
.changeset/purple-ears-sneeze.md
Normal file
5
.changeset/purple-ears-sneeze.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
perf(assets): avoid downloading original image when using cache
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue