-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix discard draft optimistic rendering #9153
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Summary
This PR implements proper cache management when deleting workflow versions by updating the Apollo cache to remove deleted versions from their parent workflow's version list.
- Added cache cleanup in
useDeleteOneWorkflowVersion.ts
usingapolloClient.cache.modify
to filter out deleted versions - Added null checks for
cachedWorkflowVersion
andcachedWorkflow
before cache modification - Uses
apolloClient.cache.identify
to correctly reference the workflow record in cache - Maintains data consistency by removing the version from both the direct record and its parent workflow's versions array
1 file(s) reviewed, 2 comment(s)
Edit PR Review Bot Settings | Greptile
}); | ||
const getWorkflowFromCache = useGetRecordFromCache({ | ||
objectNameSingular: CoreObjectNameSingular.Workflow, | ||
}); | ||
|
||
const deleteOneWorkflowVersion = async ({ | ||
workflowVersionId, | ||
}: { | ||
workflowVersionId: string; | ||
}) => { | ||
await deleteOneRecord(workflowVersionId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: deleteOneRecord could fail - wrap in try/catch to handle errors gracefully
apolloClient.cache.modify({ | ||
id: apolloClient.cache.identify(cachedWorkflow), | ||
fields: { | ||
versions: () => { | ||
return cachedWorkflow.versions.filter( | ||
(version) => version.id !== workflowVersionId, | ||
); | ||
}, | ||
}, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: cache modification happens after deletion - if deletion fails, cache will be inconsistent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Remove draft workflow version from cached workflow
Remove draft workflow version from cached workflow
Remove draft workflow version from cached workflow