Skip to content

Commit 1c0aa39

Browse files
Copilotlstein
andcommitted
Fix cache invalidation after deleting orphaned models
Co-authored-by: lstein <111189+lstein@users.noreply.github.com>
1 parent b5bd32f commit 1c0aa39

4 files changed

Lines changed: 17 additions & 18 deletions

File tree

invokeai/frontend/web/src/features/modelManagerV2/subpanels/ModelManagerPanel/SyncModelsButton.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { Button, Tooltip } from '@invoke-ai/ui-library';
2-
import { useDisclosure } from '@invoke-ai/ui-library';
1+
import { Button, Tooltip, useDisclosure } from '@invoke-ai/ui-library';
32
import { memo, useCallback } from 'react';
43
import { useTranslation } from 'react-i18next';
54
import { PiArrowsClockwiseBold } from 'react-icons/pi';

invokeai/frontend/web/src/features/modelManagerV2/subpanels/ModelManagerPanel/SyncModelsDialog.tsx

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,17 @@ export const SyncModelsDialog = memo(({ isOpen, onClose }: SyncModelsDialogProps
101101
});
102102
}, []);
103103

104+
const createToggleExpandedHandler = useCallback(
105+
(path: string) => () => handleToggleExpanded(path),
106+
[handleToggleExpanded]
107+
);
108+
109+
const createToggleModelHandler = useCallback((path: string) => () => handleToggleModel(path), [handleToggleModel]);
110+
104111
const handleDelete = useCallback(async () => {
105112
try {
106113
const result = await deleteOrphanedModels({ paths: Array.from(selectedModels) }).unwrap();
107-
114+
108115
if (result.deleted.length > 0) {
109116
toast({
110117
title: t('modelManager.orphanedModelsDeleted', { count: result.deleted.length }),
@@ -123,7 +130,7 @@ export const SyncModelsDialog = memo(({ isOpen, onClose }: SyncModelsDialogProps
123130
}
124131

125132
onClose();
126-
} catch (error) {
133+
} catch {
127134
toast({
128135
title: t('modelManager.orphanedModelsDeleteFailed'),
129136
status: 'error',
@@ -198,37 +205,27 @@ export const SyncModelsDialog = memo(({ isOpen, onClose }: SyncModelsDialogProps
198205
<Text>{t('modelManager.orphanedModelsDescription')}</Text>
199206

200207
<Flex justifyContent="space-between" alignItems="center">
201-
<Heading size="sm">
202-
{t('modelManager.foundOrphanedModels', { count: orphanedModels.length })}
203-
</Heading>
208+
<Heading size="sm">{t('modelManager.foundOrphanedModels', { count: orphanedModels.length })}</Heading>
204209
<Checkbox isChecked={selectAll} onChange={handleToggleSelectAll}>
205210
{selectAll ? t('modelManager.deselectAll') : t('modelManager.selectAll')}
206211
</Checkbox>
207212
</Flex>
208213

209214
<Flex flexDir="column" gap={2}>
210215
{orphanedModels.map((model: OrphanedModel) => (
211-
<Flex
212-
key={model.path}
213-
p={3}
214-
borderWidth={1}
215-
borderRadius="md"
216-
flexDir="column"
217-
gap={2}
218-
bg="base.750"
219-
>
216+
<Flex key={model.path} p={3} borderWidth={1} borderRadius="md" flexDir="column" gap={2} bg="base.750">
220217
<Flex justifyContent="space-between" alignItems="center">
221218
<Flex alignItems="center" gap={2} flex={1}>
222219
<IconButton
223220
aria-label={expandedModels.has(model.path) ? 'Collapse' : 'Expand'}
224221
icon={expandedModels.has(model.path) ? <PiCaretDownBold /> : <PiCaretRightBold />}
225222
size="xs"
226223
variant="ghost"
227-
onClick={() => handleToggleExpanded(model.path)}
224+
onClick={createToggleExpandedHandler(model.path)}
228225
/>
229226
<Checkbox
230227
isChecked={selectedModels.has(model.path)}
231-
onChange={() => handleToggleModel(model.path)}
228+
onChange={createToggleModelHandler(model.path)}
232229
>
233230
<Text fontWeight="semibold">{model.path}</Text>
234231
</Checkbox>

invokeai/frontend/web/src/services/api/endpoints/models.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,13 +382,15 @@ export const modelsApi = api.injectEndpoints({
382382
url: buildModelsUrl('sync/orphaned'),
383383
method: 'GET',
384384
}),
385+
providesTags: ['OrphanedModels'],
385386
}),
386387
deleteOrphanedModels: build.mutation<DeleteOrphanedModelsResponse, DeleteOrphanedModelsArg>({
387388
query: (arg) => ({
388389
url: buildModelsUrl('sync/orphaned'),
389390
method: 'DELETE',
390391
body: arg,
391392
}),
393+
invalidatesTags: ['OrphanedModels'],
392394
}),
393395
}),
394396
});

invokeai/frontend/web/src/services/api/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const tagTypes = [
3838
'ModelInstalls',
3939
'ModelRelationships',
4040
'ModelScanFolderResults',
41+
'OrphanedModels',
4142
'T2IAdapterModel',
4243
'MainModel',
4344
'VaeModel',

0 commit comments

Comments
 (0)