Block maintenanceQueue until cache is ready

pull/4602/head
awsr 2026-01-28 20:34:09 -08:00
parent 9c1f317980
commit fa0670fcd9
No known key found for this signature in database
3 changed files with 23 additions and 0 deletions

View File

@ -99,6 +99,7 @@ const jsConfig = defineConfig([
idbAdd: 'readonly',
idbCount: 'readonly',
idbFolderCleanup: 'readonly',
idbIsReady: 'readonly',
initChangelog: 'readonly',
sendNotification: 'readonly',
monitorConnection: 'readonly',

View File

@ -1212,6 +1212,22 @@ async function setOverlayAnimation() {
document.head.append(busyAnimation);
}
async function blockQueueUntilReady() {
// Add block to maintenanceQueue until cache is ready
maintenanceQueue.enqueue({
signal: new AbortSignal(), // Use standalone AbortSignal that can't be aborted
callback: async () => {
let timeout = 0;
while (!idbIsReady() && timeout++ < 60) {
await new Promise((resolve) => { setTimeout(resolve, 1000); });
}
if (!idbIsReady()) {
throw new Error('Timed out waiting for thumbnail cache');
}
},
});
}
async function initGallery() { // triggered on gradio change to monitor when ui gets sufficiently constructed
log('initGallery');
el.folders = gradioApp().getElementById('tab-gallery-folders');
@ -1222,6 +1238,8 @@ async function initGallery() { // triggered on gradio change to monitor when ui
error('initGallery', 'Missing gallery elements');
return;
}
blockQueueUntilReady(); // Run first
updateGalleryStyles();
injectGalleryStatusCSS();
setOverlayAnimation();

View File

@ -36,6 +36,10 @@ async function initIndexDB() {
if (!db) await createDB();
}
function idbIsReady() {
return db !== null;
}
/**
* Reusable setup for handling IDB transactions.
* @param {Object} resources - Required resources for implementation