Skip to content

Commit 68210ca

Browse files
cabljacCorieW
andauthored
fix!(storage-resize-images): disable backfill (#2534)
* fix!(storage-resize-images): disable backfill * fix(storage-resize-image): build * Update storage-resize-images/CHANGELOG.md * fix(storage-resize-images): format and getting rid of some backfill comments * chore(storage-resize-images): format --------- Co-authored-by: Corie Watson <[email protected]>
1 parent 04479bd commit 68210ca

File tree

9 files changed

+137
-143
lines changed

9 files changed

+137
-143
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.3.0
2+
3+
fix! - remove backfill, due to architectural flaws.
4+
15
## Version 0.2.10
26

37
feat - added param for adjusting backfill max batch size

storage-resize-images/README.md

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ You can find more information about this extension in the following articles:
144144
* Sizes of resized images: What sizes of images would you like (in pixels)? Enter the sizes as a comma-separated list of WIDTHxHEIGHT values. Learn more about [how this parameter works](https://firebase.google.com/products/extensions/storage-resize-images).
145145

146146

147-
* Deletion of original file: Do you want to automatically delete the original file from the Cloud Storage bucket? Warning: these deletions cannot be undone, and if you reconfigure this instance to use different image dimensions, you won't be able to backfill deleted images.
147+
* Deletion of original file: Do you want to automatically delete the original file from the Cloud Storage bucket? Warning: these deletions cannot be undone.
148148

149149
* Make resized images public: Do you want to make the resized images public automatically? So you can access them by URL. For example: https://storage.googleapis.com/{bucket}/{path}
150150

@@ -182,13 +182,6 @@ Leave this field empty if you do not want to store failed images in a separate d
182182

183183
* Cloud Function memory: Memory of the function responsible of resizing images. Choose how much memory to give to the function that resize images. (For animated GIF => GIF we recommend using a minimum of 2GB).
184184

185-
* Backfill existing images: Should existing, unresized images in the Storage bucket be resized as well?
186-
187-
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-
192185
* Assign new access token: Should resized images have a new access token assigned to them, different from the original image?
193186

194187

@@ -207,8 +200,6 @@ WARNING: Ensure your function has enough memory to handle the batch size.
207200

208201
* **generateResizedImage:** Listens for new images uploaded to your specified Cloud Storage bucket, resizes the images, then stores the resized images in the same bucket. Optionally keeps or deletes the original images.
209202

210-
* **backfillResizedImages:** Handles tasks from startBackfill to resize existing images.
211-
212203

213204

214205
**APIs Used**:

storage-resize-images/extension.yaml

Lines changed: 49 additions & 49 deletions
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.10
16+
version: 0.3.10
1717
specVersion: v1beta
1818

1919
displayName: Resize Images
@@ -65,14 +65,15 @@ resources:
6565
eventTrigger:
6666
eventType: google.storage.object.finalize
6767
resource: projects/_/buckets/${param:IMG_BUCKET}
68-
- name: backfillResizedImages
69-
type: firebaseextensions.v1beta.function
70-
description: >-
71-
Handles tasks from startBackfill to resize existing images.
72-
properties:
73-
runtime: nodejs20
74-
availableMemoryMb: ${param:FUNCTION_MEMORY}
75-
taskQueueTrigger: {}
68+
# Backfill feature disabled - commented out to preserve code
69+
# - name: backfillResizedImages
70+
# type: firebaseextensions.v1beta.function
71+
# description: >-
72+
# Handles tasks from startBackfill to resize existing images.
73+
# properties:
74+
# runtime: nodejs20
75+
# availableMemoryMb: ${param:FUNCTION_MEMORY}
76+
# taskQueueTrigger: {}
7677

7778
params:
7879
- param: IMG_BUCKET
@@ -111,9 +112,7 @@ params:
111112
label: Deletion of original file
112113
description: >-
113114
Do you want to automatically delete the original file from the Cloud
114-
Storage bucket? Warning: these deletions cannot be undone, and if you
115-
reconfigure this instance to use different image dimensions, you won't be
116-
able to backfill deleted images.
115+
Storage bucket? Warning: these deletions cannot be undone.
117116
type: select
118117
options:
119118
- label: Don't delete
@@ -316,32 +315,33 @@ params:
316315
required: true
317316
immutable: false
318317

319-
- param: DO_BACKFILL
320-
label: Backfill existing images
321-
description: >
322-
Should existing, unresized images in the Storage bucket be resized as
323-
well?
324-
type: select
325-
required: true
326-
options:
327-
- label: Yes
328-
value: true
329-
- label: No
330-
value: false
331-
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: string
341-
default: 3
342-
validationRegex: ^[1-9][0-9]*$
343-
validationErrorMessage: Please provide a valid number.
344-
required: false
318+
# Backfill parameters disabled - commented out to preserve code
319+
# - param: DO_BACKFILL
320+
# label: Backfill existing images
321+
# description: >
322+
# Should existing, unresized images in the Storage bucket be resized as
323+
# well?
324+
# type: select
325+
# required: true
326+
# options:
327+
# - label: Yes
328+
# value: true
329+
# - label: No
330+
# value: false
331+
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: string
341+
# default: 3
342+
# validationRegex: ^[1-9][0-9]*$
343+
# validationErrorMessage: Please provide a valid number.
344+
# required: false
345345

346346
- param: REGENERATE_TOKEN
347347
label: Assign new access token
@@ -426,14 +426,14 @@ events:
426426
description:
427427
Occurs when the function is settled. Provides no customized data other
428428
than the context.
429-
430-
lifecycleEvents:
431-
onInstall:
432-
function: backfillResizedImages
433-
processingMessage: Resizing existing images in ${param:IMG_BUCKET}
434-
onUpdate:
435-
function: backfillResizedImages
436-
processingMessage: Resizing existing images in ${param:IMG_BUCKET}
437-
onConfigure:
438-
function: backfillResizedImages
439-
processingMessage: Resizing existing images in ${param:IMG_BUCKET}
429+
# Lifecycle events disabled - backfill feature commented out
430+
# lifecycleEvents:
431+
# onInstall:
432+
# function: backfillResizedImages
433+
# processingMessage: Resizing existing images in ${param:IMG_BUCKET}
434+
# onUpdate:
435+
# function: backfillResizedImages
436+
# processingMessage: Resizing existing images in ${param:IMG_BUCKET}
437+
# onConfigure:
438+
# function: backfillResizedImages
439+
# processingMessage: Resizing existing images in ${param:IMG_BUCKET}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
export const config = {
5252
bucket: "extensions-testing.appspot.com",
5353
cacheControlHeader: undefined,
54-
doBackfill: false,
54+
// doBackfill: false,
5555
imageSizes: ["200x200"],
5656
regenerateToken: false,
5757
makePublic: false,

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@
33
exports[`extension configuration detected from environment variables 1`] = `
44
Object {
55
"animated": false,
6-
"backfillBatchSize": 3,
76
"bucket": "extensions-testing.appspot.com",
87
"cacheControlHeader": undefined,
98
"contentFilterLevel": null,
109
"customFilterPrompt": null,
1110
"deleteOriginalFile": 0,
12-
"doBackfill": false,
1311
"excludePathList": undefined,
1412
"failedImagesPath": undefined,
1513
"imageSizes": Array [

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

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

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

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

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ export const convertHarmBlockThreshold: (
6868
export const config = {
6969
bucket: process.env.IMG_BUCKET,
7070
cacheControlHeader: process.env.CACHE_CONTROL_HEADER,
71-
doBackfill: process.env.DO_BACKFILL === "true",
71+
// Backfill feature disabled - commented out to preserve code
72+
// doBackfill: process.env.DO_BACKFILL === "true",
7273
imageSizes: process.env.IMG_SIZES.split(","),
7374
regenerateToken: process.env.REGENERATE_TOKEN == "true",
7475
makePublic: process.env.MAKE_PUBLIC === "true",
@@ -88,7 +89,7 @@ export const config = {
8889
),
8990
customFilterPrompt: process.env.CUSTOM_FILTER_PROMPT || null,
9091
placeholderImagePath: process.env.PLACEHOLDER_IMAGE_PATH || null,
91-
backfillBatchSize: Number(process.env.BACKFILL_BATCH_SIZE) || 3,
92+
// backfillBatchSize: Number(process.env.BACKFILL_BATCH_SIZE) || 3,
9293
};
9394

9495
export type Config = typeof config;

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

Lines changed: 77 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -156,80 +156,80 @@ export const generateResizedImage = functions.storage
156156
/**
157157
*
158158
*/
159-
export const backfillResizedImages = functions.tasks
160-
.taskQueue()
161-
.onDispatch(async (data) => {
162-
const runtime = getExtensions().runtime();
163-
if (!config.doBackfill) {
164-
await runtime.setProcessingState(
165-
"PROCESSING_COMPLETE",
166-
"Existing images were not resized because 'Backfill existing images' was configured to false." +
167-
" If you want to resize existing images, reconfigure this instance."
168-
);
169-
return;
170-
}
171-
if (data?.nextPageQuery == undefined) {
172-
logs.startBackfill();
173-
}
174-
175-
const bucket = admin.storage().bucket(process.env.IMG_BUCKET);
176-
const query = data.nextPageQuery || {
177-
autoPaginate: false,
178-
maxResults: config.backfillBatchSize,
179-
};
180-
const [files, nextPageQuery] = await bucket.getFiles(query);
181-
const filesToResize = files.filter((f: File) => {
182-
logs.continueBackfill(f.metadata.name);
183-
return shouldResize(convertToObjectMetadata(f.metadata));
184-
});
185-
186-
const filePromises = filesToResize.map((f) => {
187-
return generateResizedImageHandler(
188-
convertToObjectMetadata(f.metadata),
189-
/*verbose=*/ false
190-
);
191-
});
192-
const results = await Promise.allSettled(filePromises);
193-
194-
const pageErrorsCount = results.filter(
195-
(r) => r.status === "rejected"
196-
).length;
197-
const pageSuccessCount = results.filter(
198-
(r) => r.status === "fulfilled"
199-
).length;
200-
const oldErrorsCount = Number(data.errorsCount) || 0;
201-
const oldSuccessCount = Number(data.successCount) || 0;
202-
const errorsCount = pageErrorsCount + oldErrorsCount;
203-
const successCount = pageSuccessCount + oldSuccessCount;
204-
205-
if (nextPageQuery) {
206-
const queue = getFunctions().taskQueue(
207-
`locations/${config.location}/functions/backfillResizedImages`,
208-
process.env.EXT_INSTANCE_ID
209-
);
210-
await queue.enqueue({
211-
nextPageQuery,
212-
errorsCount,
213-
successCount,
214-
});
215-
} else {
216-
logs.backfillComplete(successCount, errorsCount);
217-
if (errorsCount == 0) {
218-
await runtime.setProcessingState(
219-
"PROCESSING_COMPLETE",
220-
`Successfully resized ${successCount} images.`
221-
);
222-
} else if (errorsCount > 0 && successCount > 0) {
223-
await runtime.setProcessingState(
224-
"PROCESSING_WARNING",
225-
`Successfully resized ${successCount} images, failed to resize ${errorsCount} images. See function logs for error details.`
226-
);
227-
}
228-
if (errorsCount > 0 && successCount == 0) {
229-
await runtime.setProcessingState(
230-
"PROCESSING_FAILED",
231-
`Successfully resized ${successCount} images, failed to resize ${errorsCount} images. See function logs for error details.`
232-
);
233-
}
234-
}
235-
});
159+
// export const backfillResizedImages = functions.tasks
160+
// .taskQueue()
161+
// .onDispatch(async (data) => {
162+
// const runtime = getExtensions().runtime();
163+
// if (!config.doBackfill) {
164+
// await runtime.setProcessingState(
165+
// "PROCESSING_COMPLETE",
166+
// "Existing images were not resized because 'Backfill existing images' was configured to false." +
167+
// " If you want to resize existing images, reconfigure this instance."
168+
// );
169+
// return;
170+
// }
171+
// if (data?.nextPageQuery == undefined) {
172+
// logs.startBackfill();
173+
// }
174+
175+
// const bucket = admin.storage().bucket(process.env.IMG_BUCKET);
176+
// const query = data.nextPageQuery || {
177+
// autoPaginate: false,
178+
// maxResults: config.backfillBatchSize,
179+
// };
180+
// const [files, nextPageQuery] = await bucket.getFiles(query);
181+
// const filesToResize = files.filter((f: File) => {
182+
// logs.continueBackfill(f.metadata.name);
183+
// return shouldResize(convertToObjectMetadata(f.metadata));
184+
// });
185+
186+
// const filePromises = filesToResize.map((f) => {
187+
// return generateResizedImageHandler(
188+
// convertToObjectMetadata(f.metadata),
189+
// /*verbose=*/ false
190+
// );
191+
// });
192+
// const results = await Promise.allSettled(filePromises);
193+
194+
// const pageErrorsCount = results.filter(
195+
// (r) => r.status === "rejected"
196+
// ).length;
197+
// const pageSuccessCount = results.filter(
198+
// (r) => r.status === "fulfilled"
199+
// ).length;
200+
// const oldErrorsCount = Number(data.errorsCount) || 0;
201+
// const oldSuccessCount = Number(data.successCount) || 0;
202+
// const errorsCount = pageErrorsCount + oldErrorsCount;
203+
// const successCount = pageSuccessCount + oldSuccessCount;
204+
205+
// if (nextPageQuery) {
206+
// const queue = getFunctions().taskQueue(
207+
// `locations/${config.location}/functions/backfillResizedImages`,
208+
// process.env.EXT_INSTANCE_ID
209+
// );
210+
// await queue.enqueue({
211+
// nextPageQuery,
212+
// errorsCount,
213+
// successCount,
214+
// });
215+
// } else {
216+
// logs.backfillComplete(successCount, errorsCount);
217+
// if (errorsCount == 0) {
218+
// await runtime.setProcessingState(
219+
// "PROCESSING_COMPLETE",
220+
// `Successfully resized ${successCount} images.`
221+
// );
222+
// } else if (errorsCount > 0 && successCount > 0) {
223+
// await runtime.setProcessingState(
224+
// "PROCESSING_WARNING",
225+
// `Successfully resized ${successCount} images, failed to resize ${errorsCount} images. See function logs for error details.`
226+
// );
227+
// }
228+
// if (errorsCount > 0 && successCount == 0) {
229+
// await runtime.setProcessingState(
230+
// "PROCESSING_FAILED",
231+
// `Successfully resized ${successCount} images, failed to resize ${errorsCount} images. See function logs for error details.`
232+
// );
233+
// }
234+
// }
235+
// });

0 commit comments

Comments
 (0)