Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

Bug Fix: Fix workflow knowledge retrieval cache bug (#23597)

yunqiqiliangf73ec6031102
diff --git a/web/app/(commonLayout)/datasets/dataset-card.tsx b/web/app/(commonLayout)/datasets/dataset-card.tsx
index 58c82984eac..2f0563d47e4 100644
--- a/web/app/(commonLayout)/datasets/dataset-card.tsx
+++ b/web/app/(commonLayout)/datasets/dataset-card.tsx
@@ -5,6 +5,7 @@ import { useRouter } from 'next/navigation'
import { useCallback, useEffect, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { RiMoreFill } from '@remixicon/react'
+import { mutate } from 'swr'
import cn from '@/utils/classnames'
import Confirm from '@/app/components/base/confirm'
import { ToastContext } from '@/app/components/base/toast'
@@ -57,6 +58,19 @@ const DatasetCard = ({
const onConfirmDelete = useCallback(async () => {
try {
await deleteDataset(dataset.id)
+
+ // Clear SWR cache to prevent stale data in knowledge retrieval nodes
+ mutate(
+ (key) => {
+ if (typeof key === 'string') return key.includes('/datasets')
+ if (typeof key === 'object' && key !== null)
+ return key.url === '/datasets' || key.url?.includes('/datasets')
+ return false
+ },
+ undefined,
+ { revalidate: true },
+ )
+
notify({ type: 'success', message: t('dataset.datasetDeleted') })
if (onSuccess)
onSuccess()
diff --git a/web/app/components/app/configuration/dataset-config/select-dataset/index.tsx b/web/app/components/app/configuration/dataset-config/select-dataset/index.tsx
index 4c36ad9956d..4b1a5620aec 100644
--- a/web/app/components/app/configuration/dataset-config/select-dataset/index.tsx
+++ b/web/app/components/app/configuration/dataset-config/select-dataset/index.tsx
@@ -4,7 +4,6 @@ import React, { useRef, useState } from 'react'
import { useGetState, useInfiniteScroll } from 'ahooks'
import { useTranslation } from 'react-i18next'
import Link from 'next/link'
-import produce from 'immer'
import TypeIcon from '../type-icon'
import Modal from '@/app/components/base/modal'
import type { DataSet } from '@/models/datasets'
@@ -29,9 +28,10 @@ const SelectDataSet: FC<ISelectDataSetProps> = ({
onSelect,
}) => {
const { t } = useTranslation()
- const [selected, setSelected] = React.useState<DataSet[]>(selectedIds.map(id => ({ id }) as any))
+ const [selected, setSelected] = React.useState<DataSet[]>([])
const [loaded, setLoaded] = React.useState(false)
const [datasets, setDataSets] = React.useState<DataSet[] | null>(null)
+ const [hasInitialized, setHasInitialized] = React.useState(false)
const hasNoData = !datasets || datasets?.length === 0
const canSelectMulti = true
@@ -49,19 +49,17 @@ const SelectDataSet: FC<ISelectDataSetProps> = ({
const newList = [...(datasets || []), ...data.filter(item => item.indexing_technique || item.provider === 'external')]
setDataSets(newList)
setLoaded(true)
- if (!selected.find(item => !item.name))
- return { list: [] }
- const newSelected = produce(selected, (draft) => {
- selected.forEach((item, index) => {
- if (!item.name) { // not fetched database
- const newItem = newList.find(i => i.id === item.id)
- if (newItem)
- draft[index] = newItem
- }
- })
- })
- setSelected(newSelected)
+ // Initialize selected datasets based on selectedIds and available datasets
+ if (!hasInitialized) {
+ if (selectedIds.length > 0) {
+ const validSelectedDatasets = selectedIds
+ .map(id => newList.find(item => item.id === id))
+ .filter(Boolean) as DataSet[]
+ setSelected(validSelectedDatasets)
+ }
+ setHasInitialized(true)
+ }
}
return { list: [] }
},
diff --git a/web/i18n/hi-IN/share.ts b/web/i18n/hi-IN/share.ts
index a1e716b5bce..2e078a0a3b3 100644
--- a/web/i18n/hi-IN/share.ts
+++ b/web/i18n/hi-IN/share.ts
@@ -3,9 +3,6 @@ const translation = {
welcome: 'आपका स्वागत है',
appUnavailable: 'ऐप उपलब्ध नहीं है',
appUnknownError: 'अज्ञात त्रुटि, कृपया पुनः प्रयास करें',
- // @ts-expect-error TODO: fix this
-
- appUnknownError: 'ऐप अनुपलब्ध है',
},
chat: {
newChat: 'नया चैट',