Optimize Media Manager sheet update trigger

- Update mediaHandlers.ts to accept an optional forcedThumbnailUrl in updateSpreadsheetThumbnail, enabling updates without re-fetching backend state.

- Update MediaManager.html execution plan to trigger the sheet update immediately (optimistically) using the predicted first item from the plan, running in parallel with other execution phases.

- Ensure the execution flow waits for both the sheet update and other operations to complete before finishing.
This commit is contained in:
Ben Miller
2026-01-01 08:22:21 -07:00
parent 2c01693271
commit ee5fd782fe
2 changed files with 95 additions and 47 deletions

View File

@ -119,7 +119,7 @@ export function saveMediaChanges(sku: string, finalState: any[], jobId: string |
return logs
}
export function updateSpreadsheetThumbnail(sku: string) {
export function updateSpreadsheetThumbnail(sku: string, forcedThumbnailUrl: string | null = null) {
const config = new Config()
const driveService = new GASDriveService()
const shop = new Shop()
@ -128,6 +128,31 @@ export function updateSpreadsheetThumbnail(sku: string) {
const mediaService = new MediaService(driveService, shopifyMediaService, networkService, config)
const ss = new GASSpreadsheetService();
// Optimization: If forced URL provided (optimistic update), skip state calculation
if (forcedThumbnailUrl) {
try {
const row = ss.getRowNumberByColumnValue("product_inventory", "sku", sku);
if (row) {
const thumbUrl = forcedThumbnailUrl;
try {
const image = SpreadsheetApp.newCellImage()
.setSourceUrl(thumbUrl)
.setAltTextTitle(sku)
.setAltTextDescription(`Thumbnail for ${sku}`)
.build();
ss.setCellValueByColumnName("product_inventory", row, "thumbnail", image);
} catch (builderErr) {
ss.setCellValueByColumnName("product_inventory", row, "thumbnail", `=IMAGE("${thumbUrl}")`);
}
}
return;
} catch (e) {
console.warn("Failed to update sheet thumbnail (forced)", e);
throw new Error("Sheet Update Failed: " + e.message);
}
}
const product = new Product(sku);
// Need Shopify ID for accurate state logic?