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

@@ -5,6 +5,7 @@ import {CanvasInteractions} from "./CanvasInteractions.js";
import {CanvasLayers} from "./CanvasLayers.js";
import {CanvasRenderer} from "./CanvasRenderer.js";
import {CanvasIO} from "./CanvasIO.js";
import {ImageReferenceManager} from "./ImageReferenceManager.js";
import {createModuleLogger} from "./utils/LoggerUtils.js";
const log = createModuleLogger('Canvas');
@@ -42,6 +43,7 @@ export class Canvas {
this.canvasLayers = new CanvasLayers(this);
this.canvasRenderer = new CanvasRenderer(this);
this.canvasIO = new CanvasIO(this);
this.imageReferenceManager = new ImageReferenceManager(this);
this.interaction = this.canvasInteractions.interaction;
this.setupEventListeners();
@@ -372,4 +374,33 @@ export class Canvas {
showOpacitySlider(mode) {
return this.canvasLayers.showOpacitySlider(mode);
}
/**
* Ręczne uruchomienie garbage collection
*/
async runGarbageCollection() {
if (this.imageReferenceManager) {
await this.imageReferenceManager.manualGarbageCollection();
}
}
/**
* Zwraca statystyki garbage collection
*/
getGarbageCollectionStats() {
if (this.imageReferenceManager) {
return this.imageReferenceManager.getStats();
}
return null;
}
/**
* Czyści zasoby canvas (wywoływane przy usuwaniu)
*/
destroy() {
if (this.imageReferenceManager) {
this.imageReferenceManager.destroy();
}
log.info("Canvas destroyed");
}
}