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(webv2): include tags in workflow library page cache key
joshistoast1d14d9c52826
diff --git a/invokeai/frontend/webv2/src/features/workflow/data/libraryCache.test.ts b/invokeai/frontend/webv2/src/features/workflow/data/libraryCache.test.tsindex 52f9af3bc7..fbcbe30974 100644--- a/invokeai/frontend/webv2/src/features/workflow/data/libraryCache.test.ts+++ b/invokeai/frontend/webv2/src/features/workflow/data/libraryCache.test.ts@@ -81,6 +81,52 @@ describe('workflow library account ownership', () => {});});+describe('workflow library page cache keying', () => {+ beforeEach(() => {+ account.accountLifecycle.activate('user-a');+ api.listLibraryWorkflows.mockResolvedValue({ items: [], page: 1, pages: 1, per_page: 20, total: 0 });+ });++ it('keys distinct tag filters into distinct cache entries, fetching each once', async () => {+ const upscaling = { ...params, tags: ['upscaling'] };+ const lora = { ...params, tags: ['lora'] };++ await cache.listLibraryWorkflowsCached(upscaling);+ await cache.listLibraryWorkflowsCached(lora);++ expect(api.listLibraryWorkflows).toHaveBeenCalledTimes(2);+ expect(cache.getCachedWorkflowPage(upscaling)).not.toBeNull();+ expect(cache.getCachedWorkflowPage(lora)).not.toBeNull();+ });++ it('hits the cache for a repeat request with the same tags regardless of order', async () => {+ const first = { ...params, tags: ['lora', 'upscaling'] };+ const second = { ...params, tags: ['upscaling', 'lora'] };++ await cache.listLibraryWorkflowsCached(first);++ // A single fetch populates the cache under a tag-order-normalized key, so a+ // differently-ordered request for the same tag set reads the same entry+ // synchronously without triggering another fetch.+ expect(api.listLibraryWorkflows).toHaveBeenCalledTimes(1);+ expect(cache.getCachedWorkflowPage(second)).not.toBeNull();+ expect(cache.getCachedWorkflowPage(second)).toBe(cache.getCachedWorkflowPage(first));+ });++ it('does not collide an untagged request with a tagged one for the same page', async () => {+ const untagged = params;+ const tagged = { ...params, tags: ['lora'] };++ await cache.listLibraryWorkflowsCached(untagged);++ expect(cache.getCachedWorkflowPage(tagged)).toBeNull();++ await cache.listLibraryWorkflowsCached(tagged);++ expect(api.listLibraryWorkflows).toHaveBeenCalledTimes(2);+ });+});+describe('workflow library cache invalidation listeners', () => {it('notifies registered listeners when the cache is invalidated', () => {const listener = vi.fn();diff --git a/invokeai/frontend/webv2/src/features/workflow/data/libraryCache.ts b/invokeai/frontend/webv2/src/features/workflow/data/libraryCache.tsindex 653c7a68e1..bb7b9254da 100644--- a/invokeai/frontend/webv2/src/features/workflow/data/libraryCache.ts+++ b/invokeai/frontend/webv2/src/features/workflow/data/libraryCache.ts@@ -16,8 +16,11 @@ import { getLibraryWorkflow, listLibraryWorkflows, type ListWorkflowsParams, typconst pageCache = new Map<string, WorkflowLibraryPage>();const workflowCache = new Map<string, Record<string, unknown>>();+/** `JSON.stringify` on a sorted copy avoids delimiter collisions between tag values. */+const getTagsKey = (tags: string[] | undefined): string => JSON.stringify([...(tags ?? [])].sort());+const getPageKey = (params: ListWorkflowsParams): string =>- `${params.category}|${params.page}|${params.perPage ?? 20}|${params.query?.trim() ?? ''}`;+ `${params.category}|${params.page}|${params.perPage ?? 20}|${params.query?.trim() ?? ''}|${getTagsKey(params.tags)}`;export const getCachedWorkflowPage = (params: ListWorkflowsParams): WorkflowLibraryPage | null =>pageCache.get(getPageKey(params)) ?? null;