Add image garbage collection to canvas

Introduced ImageReferenceManager to track and clean up unused images from the database and cache. Added manual garbage collection controls to the UI and exposed related stats and cleanup methods in Canvas. Updated db.js with a method to retrieve all image IDs for cleanup purposes.
This commit is contained in:
Dariusz L
2025-06-26 18:28:50 +02:00
parent dd6a9dfc85
commit 7d7076cc45
4 changed files with 354 additions and 0 deletions

View File

@@ -146,6 +146,28 @@ export async function removeImage(imageId) {
log.debug(`Remove image success for id: ${imageId}`);
}
export async function getAllImageIds() {
log.info("Getting all image IDs...");
const db = await openDB();
const transaction = db.transaction([IMAGE_STORE_NAME], 'readonly');
const store = transaction.objectStore(IMAGE_STORE_NAME);
return new Promise((resolve, reject) => {
const request = store.getAllKeys();
request.onerror = (event) => {
log.error("Error getting all image IDs:", event.target.error);
reject("Error getting all image IDs");
};
request.onsuccess = (event) => {
const imageIds = event.target.result;
log.debug(`Found ${imageIds.length} image IDs in database`);
resolve(imageIds);
};
});
}
export async function clearAllCanvasStates() {
log.info("Clearing all canvas states...");
const db = await openDB();