From 511d272d0d378c3708252d7fb65d8d64fcd8725c Mon Sep 17 00:00:00 2001 From: balibabu Date: Wed, 9 Oct 2024 15:28:28 +0800 Subject: [PATCH] feat: The same query conditions on the search page should not request the interface every time the mind map drawer is opened. #2759 (#2760) ### What problem does this PR solve? feat: The same query conditions on the search page should not request the interface every time the mind map drawer is opened. #2759 ### Type of change - [ ] Bug Fix (non-breaking change which fixes an issue) - [x] New Feature (non-breaking change which adds functionality) - [ ] Documentation Update - [ ] Refactoring - [ ] Performance Improvement - [ ] Other (please describe): --- web/src/pages/search/hooks.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/web/src/pages/search/hooks.ts b/web/src/pages/search/hooks.ts index 062067a3a..20546e0d9 100644 --- a/web/src/pages/search/hooks.ts +++ b/web/src/pages/search/hooks.ts @@ -7,7 +7,7 @@ import { } from '@/hooks/logic-hooks'; import { IAnswer } from '@/interfaces/database/chat'; import api from '@/utils/api'; -import { get, isEmpty, trim } from 'lodash'; +import { get, isEmpty, isEqual, trim } from 'lodash'; import { ChangeEventHandler, useCallback, @@ -188,6 +188,7 @@ export const useTestRetrieval = ( export const useShowMindMapDrawer = (kbIds: string[], question: string) => { const { visible, showModal, hideModal } = useSetModalState(); + const ref = useRef(); const { fetchMindMap, @@ -196,7 +197,14 @@ export const useShowMindMapDrawer = (kbIds: string[], question: string) => { } = useFetchMindMap(); const handleShowModal = useCallback(() => { - fetchMindMap({ question: trim(question), kb_ids: kbIds }); + const searchParams = { question: trim(question), kb_ids: kbIds }; + if ( + !isEmpty(searchParams.question) && + !isEqual(searchParams, ref.current) + ) { + ref.current = searchParams; + fetchMindMap(searchParams); + } showModal(); }, [fetchMindMap, showModal, question, kbIds]);