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): deduplicate saved workflow invalidation fetches
JPPhoto51856195ed3f
diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/editor/CallSavedWorkflowSyncRuntime.browser.test.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/editor/CallSavedWorkflowSyncRuntime.browser.test.tsxindex 430b7db466..a09b52fef0 100644--- a/invokeai/frontend/webv2/src/features/workflow/ui/editor/CallSavedWorkflowSyncRuntime.browser.test.tsx+++ b/invokeai/frontend/webv2/src/features/workflow/ui/editor/CallSavedWorkflowSyncRuntime.browser.test.tsx@@ -219,6 +219,38 @@ describe('CallSavedWorkflowSyncRuntime with an unreachable child workflow', () =await expectSettled(readGraph, ['error', 'error'], 1);});+ it('refetches an invalidated workflow once for multiple call nodes', async () => {+ const { readGraph } = await mountWith([+ buildCallNode('call-1'),+ buildCallNode('call-2'),+ buildCallNode('call-3'),+ ]);++ await expectSettled(readGraph, ['error', 'error', 'error'], 1);++ invalidateWorkflowLibraryCache(MISSING_WORKFLOW_ID);+ await settle(250);++ expect(getLibraryWorkflowRecordMock).toHaveBeenCalledTimes(2);+ expect(readStatuses(readGraph())).toEqual(['error', 'error', 'error']);+ });++ it('keeps an invalidation retry available when the first matching node changes', async () => {+ const attempts = mockWorkflowThatRecoversAfterOneFailure(MISSING_WORKFLOW_ID);+ const { readGraph, updateGraph } = await mountWith([+ buildCallNode('call-1'),+ buildCallNode('call-2'),+ ]);++ await settle(60);+ invalidateWorkflowLibraryCache(MISSING_WORKFLOW_ID);+ selectWorkflow(readGraph, updateGraph, 'other-workflow');+ await settle(60);++ expect(attempts.filter((id) => id === MISSING_WORKFLOW_ID)).toHaveLength(2);+ expect(readStatuses(readGraph())).toEqual(['error', 'ready']);+ });+it('keeps recalled dynamic fields visible when the child workflow is unavailable', async () => {const { readGraph } = await mountWith([buildCallNode('call-1', MISSING_WORKFLOW_ID, true)]);diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/editor/CallSavedWorkflowSyncRuntime.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/editor/CallSavedWorkflowSyncRuntime.tsxindex c887c75048..9c8ed058a8 100644--- a/invokeai/frontend/webv2/src/features/workflow/ui/editor/CallSavedWorkflowSyncRuntime.tsx+++ b/invokeai/frontend/webv2/src/features/workflow/ui/editor/CallSavedWorkflowSyncRuntime.tsx@@ -138,6 +138,7 @@ export const CallSavedWorkflowSyncRuntime = () => {const queryClient = useQueryClient();const { commands, project: projectPort } = useWorkflowUi();const retryableDetailWorkflowIds = useRef(new Map<string, string>());+ const retryableDetailWorkflowQueries = useRef(new Set<string>());const previousDetailWorkflowIds = useRef(new Map<string, string>());const previousDetailStatuses = useRef(new Map<string, 'loading' | 'ready' | 'error'>());const parseChildWorkflow = useMemo(() => createSavedWorkflowDocumentParser(), []);@@ -225,7 +226,9 @@ export const CallSavedWorkflowSyncRuntime = () => {retryableDetailWorkflowIds.current.set(node.id, workflowId);}- const retryWasAuthorized = retryableDetailWorkflowIds.current.get(node.id) === workflowId;+ const retryWasAuthorized =+ retryableDetailWorkflowIds.current.get(node.id) === workflowId ||+ retryableDetailWorkflowQueries.current.has(workflowId);if (shouldFetchSavedWorkflowDetail(query, {@@ -244,11 +247,13 @@ export const CallSavedWorkflowSyncRuntime = () => {if (retryableDetailWorkflowIds.current.get(node.id) === workflowId) {retryableDetailWorkflowIds.current.delete(node.id);}+ retryableDetailWorkflowQueries.current.delete(workflowId);}).catch(() => {if (retryableDetailWorkflowIds.current.get(node.id) === workflowId) {retryableDetailWorkflowIds.current.delete(node.id);}+ retryableDetailWorkflowQueries.current.delete(workflowId);const failedQuery = queryClient.getQueryCache().find({ queryKey: detailOptions.queryKey });const currentNode = projectPort.getSnapshot()@@ -337,16 +342,12 @@ export const CallSavedWorkflowSyncRuntime = () => {}});const unsubscribeLibrary = onWorkflowLibraryCacheInvalidated((workflowId) => {+ const authorizeWorkflowRetry = (workflowId: string) => {+ retryableDetailWorkflowQueries.current.add(workflowId);+ };+if (workflowId) {- for (const node of projectPort.getSnapshot().projectGraph.nodes) {- if (- node.type === 'invocation' &&- node.data.type === 'call_saved_workflow' &&- node.data.inputs.workflow_id?.value === workflowId- ) {- retryableDetailWorkflowIds.current.set(node.id, workflowId);- }- }+ authorizeWorkflowRetry(workflowId);void queryClient.invalidateQueries({exact: true,queryKey: savedWorkflowDetailQueryKey(workflowId),@@ -355,15 +356,7 @@ export const CallSavedWorkflowSyncRuntime = () => {} else {for (const query of queryClient.getQueryCache().findAll({ queryKey: ['workflow', 'call-saved', 'detail'] })) {if (isSavedWorkflowDetailQueryKey(query.queryKey)) {- for (const node of projectPort.getSnapshot().projectGraph.nodes) {- if (- node.type === 'invocation' &&- node.data.type === 'call_saved_workflow' &&- node.data.inputs.workflow_id?.value === query.queryKey[3]- ) {- retryableDetailWorkflowIds.current.set(node.id, query.queryKey[3]);- }- }+ authorizeWorkflowRetry(query.queryKey[3]);}}