Skip to content

Commit 43392d1

Browse files
authored
feat(storage-resize-image): add param for backfill batch size (#2478)
* feat(storage-resize-image): add param for backfill batch size * chore(storage-resize-images): format * fix(storage-resize-image): tests * feat: add validation of batch size param
1 parent 10c7b53 commit 43392d1

File tree

8 files changed

+28
-2
lines changed

8 files changed

+28
-2
lines changed

storage-resize-images/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## Version 0.2.10
2+
3+
feat - added param for adjusting backfill max batch size
4+
15
## Version 0.2.9
26

37
fixed - run an npm audit and bump vulnerable dependencies

storage-resize-images/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ Leave this field empty if you do not want to store failed images in a separate d
185185
* Backfill existing images: Should existing, unresized images in the Storage bucket be resized as well?
186186

187187

188+
* Backfill batch size: The maximum number of images to resize in a single batch. By default, the function is configured to resize 3 images at a time. This is a conservative default to work with smallest memory option (512 MB).
189+
WARNING: Ensure your function has enough memory to handle the batch size.
190+
191+
188192
* Assign new access token: Should resized images have a new access token assigned to them, different from the original image?
189193

190194

storage-resize-images/extension.yaml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
name: storage-resize-images
16-
version: 0.2.9
16+
version: 0.2.10
1717
specVersion: v1beta
1818

1919
displayName: Resize Images
@@ -329,6 +329,20 @@ params:
329329
- label: No
330330
value: false
331331

332+
- param: BACKFILL_BATCH_SIZE
333+
label: Backfill batch size
334+
description: >
335+
The maximum number of images to resize in a single batch. By default, the
336+
function is configured to resize 3 images at a time. This is a
337+
conservative default to work with smallest memory option (512 MB).
338+
339+
WARNING: Ensure your function has enough memory to handle the batch size.
340+
type: number
341+
default: 3
342+
validationRegex: ^[1-9][0-9]*$
343+
validationErrorMessage: Please provide a valid number.
344+
required: false
345+
332346
- param: REGENERATE_TOKEN
333347
label: Assign new access token
334348
description: >

storage-resize-images/functions/__tests__/__snapshots__/config.test.ts.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
exports[`extension configuration detected from environment variables 1`] = `
44
Object {
55
"animated": false,
6+
"backfillBatchSize": 3,
67
"bucket": "extensions-testing.appspot.com",
78
"cacheControlHeader": undefined,
89
"contentFilterLevel": null,

storage-resize-images/functions/__tests__/filters.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ jest.mock("../src/config", () => {
1111
imgSizes: ["200x200"],
1212
resizedImagesPath: undefined,
1313
deleteOriginalFile: "true",
14+
backfillBatchSize: 3,
1415
},
1516
};
1617
});

storage-resize-images/functions/__tests__/function.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ jest.mock("../src/config", () => {
2727
imgSizes: ["200x200"],
2828
resizedImagesPath: undefined,
2929
deleteOriginalFile: "true",
30+
backfillBatchSize: 3,
3031
},
3132
};
3233
});

storage-resize-images/functions/src/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export const config = {
8888
),
8989
customFilterPrompt: process.env.CUSTOM_FILTER_PROMPT || null,
9090
placeholderImagePath: process.env.PLACEHOLDER_IMAGE_PATH || null,
91+
backfillBatchSize: Number(process.env.BACKFILL_BATCH_SIZE) || 3,
9192
};
9293

9394
export type Config = typeof config;

storage-resize-images/functions/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ export const backfillResizedImages = functions.tasks
175175
const bucket = admin.storage().bucket(process.env.IMG_BUCKET);
176176
const query = data.nextPageQuery || {
177177
autoPaginate: false,
178-
maxResults: 3, // We only grab 3 images at a time to minimize the chance of OOM errors.
178+
maxResults: config.backfillBatchSize,
179179
};
180180
const [files, nextPageQuery] = await bucket.getFiles(query);
181181
const filesToResize = files.filter((f: File) => {

0 commit comments

Comments
 (0)