Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
fix(ui): order relationship cache writes across late responses
Josh Corbett09cbc475bbf6
diff --git a/invokeai/frontend/webv2/src/features/models/data/relationshipsStore.test.ts b/invokeai/frontend/webv2/src/features/models/data/relationshipsStore.test.tsindex ea618826e1..576379ae14 100644--- a/invokeai/frontend/webv2/src/features/models/data/relationshipsStore.test.ts+++ b/invokeai/frontend/webv2/src/features/models/data/relationshipsStore.test.ts@@ -148,6 +148,64 @@ describe('relationships store', () => {expect(api.getRelatedModelKeys).toHaveBeenCalledTimes(1);});+ it('a link that settles after its model was deleted does not resurrect it', async () => {+ let resolveLink: (() => void) | undefined;+ api.addModelRelationship.mockReturnValueOnce(+ new Promise<void>((resolve) => {+ resolveLink = resolve;+ })+ );+ const store = await import('./relationshipsStore');+ store.setRelationshipsSnapshotForTests({ relatedKeysByModelKey: { a: [], b: [] } });++ const link = store.linkModels('a', 'b');+ store.removeModelsFromRelationships(['b']);++ resolveLink?.();+ await link;++ expect(store.getRelationshipsSnapshot().relatedKeysByModelKey).toEqual({ a: [] });+ });++ it('a link that settles after a newer unlink of the same pair does not re-add it', async () => {+ let resolveLink: (() => void) | undefined;+ api.addModelRelationship.mockReturnValueOnce(+ new Promise<void>((resolve) => {+ resolveLink = resolve;+ })+ );+ const store = await import('./relationshipsStore');+ store.setRelationshipsSnapshotForTests({ relatedKeysByModelKey: { a: [], b: [] } });++ const link = store.linkModels('a', 'b');+ // The unlink is issued from the other side of the pair and settles first.+ await store.unlinkModels('b', 'a');++ resolveLink?.();+ await link;++ expect(store.getRelationshipsSnapshot().relatedKeysByModelKey).toEqual({ a: [], b: [] });+ });++ it('an unlink that settles after a newer link does not clobber it', async () => {+ let resolveUnlink: (() => void) | undefined;+ api.removeModelRelationship.mockReturnValueOnce(+ new Promise<void>((resolve) => {+ resolveUnlink = resolve;+ })+ );+ const store = await import('./relationshipsStore');+ store.setRelationshipsSnapshotForTests({ relatedKeysByModelKey: { a: ['b'], b: ['a'] } });++ const unlink = store.unlinkModels('a', 'b');+ await store.linkModels('a', 'b');++ resolveUnlink?.();+ await unlink;++ expect(store.getRelationshipsSnapshot().relatedKeysByModelKey).toEqual({ a: ['b'], b: ['a'] });+ });+it('clears the cache and inflight requests on account switch', async () => {const account = await import('@platform/state/accountLifecycle');account.accountLifecycle.activate('user-a');diff --git a/invokeai/frontend/webv2/src/features/models/data/relationshipsStore.ts b/invokeai/frontend/webv2/src/features/models/data/relationshipsStore.tsindex 8e628f8e8d..7250f03351 100644Binary files a/invokeai/frontend/webv2/src/features/models/data/relationshipsStore.ts and b/invokeai/frontend/webv2/src/features/models/data/relationshipsStore.ts differ