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:
@ -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?
|
||||
|
||||
Reference in New Issue
Block a user