feat(ui): omit non-render-impacting keys when hashing entities

Had missed several of these, which means we were invalidating caches far too often. For example, when you changed a RG prompt, we were invalidating the cached canvas for that entity, even though changing the prompt doesn't affect the canvas at all.
This commit is contained in:
psychedelicious
2024-10-30 09:32:09 +10:00
parent a4629280b5
commit f4b7c63002
5 changed files with 17 additions and 5 deletions

View File

@@ -97,7 +97,10 @@ export abstract class CanvasEntityAdapterBase<
abstract getCanvas: (rect?: Rect) => HTMLCanvasElement;
/**
* Gets a hashable representation of the entity's state.
* Gets a hashable representation of the entity's _renderable_ state. This should exclude any properties that are not
* relevant to rendering the entity.
*
* This is used for caching.
*/
abstract getHashableState: () => SerializableObject;

View File

@@ -78,7 +78,7 @@ export class CanvasEntityAdapterControlLayer extends CanvasEntityAdapterBase<
};
getHashableState = (): SerializableObject => {
const keysToOmit: (keyof CanvasControlLayerState)[] = ['name', 'controlAdapter', 'withTransparencyEffect'];
const keysToOmit: (keyof CanvasControlLayerState)[] = ['name', 'controlAdapter', 'withTransparencyEffect', 'isLocked'];
return omit(this.state, keysToOmit);
};
}

View File

@@ -70,7 +70,7 @@ export class CanvasEntityAdapterInpaintMask extends CanvasEntityAdapterBase<
};
getHashableState = (): SerializableObject => {
const keysToOmit: (keyof CanvasInpaintMaskState)[] = ['fill', 'name', 'opacity'];
const keysToOmit: (keyof CanvasInpaintMaskState)[] = ['fill', 'name', 'opacity', 'isLocked'];
return omit(this.state, keysToOmit);
};

View File

@@ -71,7 +71,7 @@ export class CanvasEntityAdapterRasterLayer extends CanvasEntityAdapterBase<
};
getHashableState = (): SerializableObject => {
const keysToOmit: (keyof CanvasRasterLayerState)[] = ['name'];
const keysToOmit: (keyof CanvasRasterLayerState)[] = ['name', 'isLocked'];
return omit(this.state, keysToOmit);
};
}

View File

@@ -70,7 +70,16 @@ export class CanvasEntityAdapterRegionalGuidance extends CanvasEntityAdapterBase
};
getHashableState = (): SerializableObject => {
const keysToOmit: (keyof CanvasRegionalGuidanceState)[] = ['fill', 'name', 'opacity'];
const keysToOmit: (keyof CanvasRegionalGuidanceState)[] = [
'fill',
'name',
'opacity',
'isLocked',
'autoNegative',
'positivePrompt',
'negativePrompt',
'referenceImages',
];
return omit(this.state, keysToOmit);
};