mirror of
https://github.com/Azornes/Comfyui-LayerForge.git
synced 2026-03-24 22:12:17 -03:00
Add operation-based auto garbage collection for images
Introduces an operation counter and threshold in ImageReferenceManager to trigger automatic garbage collection after a set number of canvas operations. Canvas now increments the operation count on save, undo, and redo, and exposes methods to set the operation threshold and retrieve stats including operation count. CanvasView displays the operation count and threshold after manual garbage collection.
This commit is contained in:
28
js/Canvas.js
28
js/Canvas.js
@@ -78,14 +78,17 @@ export class Canvas {
|
||||
|
||||
saveState(replaceLast = false) {
|
||||
this.canvasState.saveState(replaceLast);
|
||||
this.incrementOperationCount();
|
||||
}
|
||||
|
||||
undo() {
|
||||
this.canvasState.undo();
|
||||
this.incrementOperationCount();
|
||||
}
|
||||
|
||||
redo() {
|
||||
this.canvasState.redo();
|
||||
this.incrementOperationCount();
|
||||
}
|
||||
|
||||
updateSelectionAfterHistory() {
|
||||
@@ -376,6 +379,15 @@ export class Canvas {
|
||||
return this.canvasLayers.showOpacitySlider(mode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Zwiększa licznik operacji (wywoływane przy każdej operacji na canvas)
|
||||
*/
|
||||
incrementOperationCount() {
|
||||
if (this.imageReferenceManager) {
|
||||
this.imageReferenceManager.incrementOperationCount();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ręczne uruchomienie garbage collection
|
||||
*/
|
||||
@@ -390,11 +402,25 @@ export class Canvas {
|
||||
*/
|
||||
getGarbageCollectionStats() {
|
||||
if (this.imageReferenceManager) {
|
||||
return this.imageReferenceManager.getStats();
|
||||
const stats = this.imageReferenceManager.getStats();
|
||||
return {
|
||||
...stats,
|
||||
operationCount: this.imageReferenceManager.operationCount,
|
||||
operationThreshold: this.imageReferenceManager.operationThreshold
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ustawia próg operacji dla automatycznego GC
|
||||
*/
|
||||
setGarbageCollectionThreshold(threshold) {
|
||||
if (this.imageReferenceManager) {
|
||||
this.imageReferenceManager.setOperationThreshold(threshold);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Czyści zasoby canvas (wywoływane przy usuwaniu)
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user