Optimize media manager polling and product info retrieval

- Remove recursive polling in MediaManager.html; context is now loaded once at startup.
- Optimize getSelectedProductInfo in mediaHandlers.ts to reduce SpreadsheetApp API calls.
- Update related tests to match new optimization.
This commit is contained in:
Ben Miller
2025-12-31 08:53:39 -07:00
parent ad67dd9ab5
commit 8487df3ea0
3 changed files with 57 additions and 5 deletions

View File

@ -1206,8 +1206,8 @@
*/
var controller = {
init() {
// Start polling for SKU selection
setInterval(() => this.checkSku(), 2000);
// Initialize by checking SKU once
// Since this is a modal, the selection cannot change during the session.
this.checkSku();
},
@ -1222,10 +1222,19 @@
this.loadMedia();
} else if (!sku && !state.sku) {
if (document.getElementById('error-ui').style.display !== 'flex') {
this.loadMedia();
this.loadMedia(); // Likely to trigger error UI
}
}
})
.withFailureHandler(e => {
console.warn("SKU check failed", e);
// If it fails once at startup, we probably should alert or retry once,
// but for now let's just leave it. If it fails, the UI might hang on "Loading..."
// potentially better to trigger error UI?
if (document.getElementById('loading-ui').style.display !== 'none') {
alert("Failed to load product info: " + e.message);
}
})
.getSelectedProductInfo();
},