From cf633e4ef251a9b0c0ca97c087b7a96c6ac03435 Mon Sep 17 00:00:00 2001 From: Brandon Rising Date: Mon, 26 Aug 2024 12:54:28 -0400 Subject: [PATCH] Only install starter models if not already installed --- .../StarterModels/StartModelsResultItem.tsx | 9 +++++++-- .../StarterModels/StarterModelsForm.tsx | 20 ++++++++++++++++--- .../StarterModels/StarterModelsResults.tsx | 6 ++++-- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/invokeai/frontend/web/src/features/modelManagerV2/subpanels/AddModelPanel/StarterModels/StartModelsResultItem.tsx b/invokeai/frontend/web/src/features/modelManagerV2/subpanels/AddModelPanel/StarterModels/StartModelsResultItem.tsx index f85b124b21..81913f3e8e 100644 --- a/invokeai/frontend/web/src/features/modelManagerV2/subpanels/AddModelPanel/StarterModels/StartModelsResultItem.tsx +++ b/invokeai/frontend/web/src/features/modelManagerV2/subpanels/AddModelPanel/StarterModels/StartModelsResultItem.tsx @@ -5,11 +5,13 @@ import { memo, useCallback, useMemo } from 'react'; import { useTranslation } from 'react-i18next'; import { PiPlusBold } from 'react-icons/pi'; import type { GetStarterModelsResponse } from 'services/api/endpoints/models'; +import type { AnyModelConfig } from 'services/api/types'; type Props = { result: GetStarterModelsResponse[number]; + modelList: AnyModelConfig[]; }; -export const StarterModelsResultItem = memo(({ result }: Props) => { +export const StarterModelsResultItem = memo(({ result, modelList }: Props) => { const { t } = useTranslation(); const allSources = useMemo(() => { const _allSources = [ @@ -38,9 +40,12 @@ export const StarterModelsResultItem = memo(({ result }: Props) => { const onClick = useCallback(() => { for (const { config, source } of allSources) { + if (modelList.some((mc) => config.base === mc.base && config.name === mc.name && config.type === mc.type)) { + continue; + } installModel({ config, source }); } - }, [allSources, installModel]); + }, [modelList, allSources, installModel]); return ( diff --git a/invokeai/frontend/web/src/features/modelManagerV2/subpanels/AddModelPanel/StarterModels/StarterModelsForm.tsx b/invokeai/frontend/web/src/features/modelManagerV2/subpanels/AddModelPanel/StarterModels/StarterModelsForm.tsx index 837ef5c63b..eaf2cb534e 100644 --- a/invokeai/frontend/web/src/features/modelManagerV2/subpanels/AddModelPanel/StarterModels/StarterModelsForm.tsx +++ b/invokeai/frontend/web/src/features/modelManagerV2/subpanels/AddModelPanel/StarterModels/StarterModelsForm.tsx @@ -1,17 +1,31 @@ import { Flex } from '@invoke-ai/ui-library'; +import { EMPTY_ARRAY } from 'app/store/constants'; import { FetchingModelsLoader } from 'features/modelManagerV2/subpanels/ModelManagerPanel/FetchingModelsLoader'; -import { memo } from 'react'; -import { useGetStarterModelsQuery } from 'services/api/endpoints/models'; +import { memo, useMemo } from 'react'; +import { + modelConfigsAdapterSelectors, + useGetModelConfigsQuery, + useGetStarterModelsQuery, +} from 'services/api/endpoints/models'; import { StarterModelsResults } from './StarterModelsResults'; export const StarterModelsForm = memo(() => { const { isLoading, data } = useGetStarterModelsQuery(); + const { data: modelListRes } = useGetModelConfigsQuery(); + + const modelList = useMemo(() => { + if (!modelListRes) { + return EMPTY_ARRAY; + } + + return modelConfigsAdapterSelectors.selectAll(modelListRes); + }, [modelListRes]); return ( {isLoading && } - {data && } + {data && } ); }); diff --git a/invokeai/frontend/web/src/features/modelManagerV2/subpanels/AddModelPanel/StarterModels/StarterModelsResults.tsx b/invokeai/frontend/web/src/features/modelManagerV2/subpanels/AddModelPanel/StarterModels/StarterModelsResults.tsx index e593ee5fc3..c443171060 100644 --- a/invokeai/frontend/web/src/features/modelManagerV2/subpanels/AddModelPanel/StarterModels/StarterModelsResults.tsx +++ b/invokeai/frontend/web/src/features/modelManagerV2/subpanels/AddModelPanel/StarterModels/StarterModelsResults.tsx @@ -5,14 +5,16 @@ import { memo, useCallback, useMemo, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { PiXBold } from 'react-icons/pi'; import type { GetStarterModelsResponse } from 'services/api/endpoints/models'; +import type { AnyModelConfig } from 'services/api/types'; import { StarterModelsResultItem } from './StartModelsResultItem'; type StarterModelsResultsProps = { results: NonNullable; + modelList: AnyModelConfig[]; }; -export const StarterModelsResults = memo(({ results }: StarterModelsResultsProps) => { +export const StarterModelsResults = memo(({ results, modelList }: StarterModelsResultsProps) => { const { t } = useTranslation(); const [searchTerm, setSearchTerm] = useState(''); @@ -72,7 +74,7 @@ export const StarterModelsResults = memo(({ results }: StarterModelsResultsProps {filteredResults.map((result) => ( - + ))}