File tree Expand file tree Collapse file tree 2 files changed +19
-4
lines changed
app/workspace/[workspaceId]/knowledge/[id] Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -62,7 +62,7 @@ import {
6262 type TagDefinition ,
6363 useKnowledgeBaseTagDefinitions ,
6464} from '@/hooks/kb/use-knowledge-base-tag-definitions'
65- import { useConnectorList } from '@/hooks/queries/kb/connectors'
65+ import { isConnectorSyncingOrPending , useConnectorList } from '@/hooks/queries/kb/connectors'
6666import type { DocumentTagFilter } from '@/hooks/queries/kb/knowledge'
6767import {
6868 useBulkDocumentOperation ,
@@ -272,7 +272,7 @@ export function KnowledgeBase({
272272 } = useKnowledgeBase ( id )
273273
274274 const { data : connectors = [ ] , isLoading : isLoadingConnectors } = useConnectorList ( id )
275- const hasSyncingConnectors = connectors . some ( ( c ) => c . status === 'syncing' )
275+ const hasSyncingConnectors = connectors . some ( isConnectorSyncingOrPending )
276276 const hasSyncingConnectorsRef = useRef ( hasSyncingConnectors )
277277 hasSyncingConnectorsRef . current = hasSyncingConnectors
278278
Original file line number Diff line number Diff line change @@ -88,6 +88,21 @@ async function fetchConnectorDetail(
8888 return result . data
8989}
9090
91+ /** Stop polling for initial sync after 2 minutes */
92+ const PENDING_SYNC_WINDOW_MS = 2 * 60 * 1000
93+
94+ /**
95+ * Checks if a connector is syncing or awaiting its first sync within the allowed window
96+ */
97+ export function isConnectorSyncingOrPending ( connector : ConnectorData ) : boolean {
98+ if ( connector . status === 'syncing' ) return true
99+ return (
100+ connector . status === 'active' &&
101+ ! connector . lastSyncAt &&
102+ Date . now ( ) - new Date ( connector . createdAt ) . getTime ( ) < PENDING_SYNC_WINDOW_MS
103+ )
104+ }
105+
91106export function useConnectorList ( knowledgeBaseId ?: string ) {
92107 return useQuery ( {
93108 queryKey : connectorKeys . list ( knowledgeBaseId ) ,
@@ -97,8 +112,8 @@ export function useConnectorList(knowledgeBaseId?: string) {
97112 placeholderData : keepPreviousData ,
98113 refetchInterval : ( query ) => {
99114 const connectors = query . state . data
100- const hasSyncing = connectors ?. some ( ( c ) => c . status === 'syncing' )
101- return hasSyncing ? 3000 : false
115+ if ( ! connectors ?. length ) return false
116+ return connectors . some ( isConnectorSyncingOrPending ) ? 3000 : false
102117 } ,
103118 } )
104119}
You can’t perform that action at this time.
0 commit comments