Repository navigation
Fix: show tag list for chunk - #15251
Conversation
📝 WalkthroughWalkthroughThe hook ChangesTag List Query Caching and Normalization
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Caution Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted. Error details |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
web/src/hooks/use-knowledge-request.ts (1)
505-512: ⚡ Quick winStabilize
knowledgeIdsordering inuseFetchTagListByKnowledgeIdsto avoid duplicate React Query cache entries
queryKeyanddataset_idsboth use the rawknowledgeIdsarray order; callers populateknowledgeIdsfromparser_config.tag_kb_ids(user-driven viaMultiSelect), so the same ID set can arrive in different orders and produce separate cache buckets/extra fetches. Sorting once for both the key and payload prevents this.Proposed change
export const useFetchTagListByKnowledgeIds = () => { const [knowledgeIds, setKnowledgeIds] = useState<string[]>([]); + const sortedKnowledgeIds = useMemo( + () => [...knowledgeIds].sort(), + [knowledgeIds], + ); const { data, isFetching: loading } = useQuery<Array<[string, number]>>({ - queryKey: ['fetchTagListByKnowledgeIds', knowledgeIds], - enabled: knowledgeIds.length > 0, + queryKey: ['fetchTagListByKnowledgeIds', sortedKnowledgeIds], + enabled: sortedKnowledgeIds.length > 0, initialData: [], gcTime: 0, // https://tanstack.com/query/latest/docs/framework/react/guides/caching?from=reactQueryV3 queryFn: async () => { const { data } = await kbService.listTagByKnowledgeIds({ - dataset_ids: knowledgeIds.join(','), + dataset_ids: sortedKnowledgeIds.join(','), });Run
npm run lintinweb/to ensure the change passes ESLint.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@web/src/hooks/use-knowledge-request.ts` around lines 505 - 512, The query uses the raw knowledgeIds array in the queryKey and in the payload (kbService.listTagByKnowledgeIds), causing cache duplication when callers supply the same IDs in different orders; fix by creating a stable sorted array (e.g., sortedKnowledgeIds = [...knowledgeIds].sort()) and use sortedKnowledgeIds in the queryKey (replace usage of knowledgeIds) and when building dataset_ids (use sortedKnowledgeIds.join(',')), keep the enabled check (knowledgeIds.length > 0) the same, and run npm run lint in web/ to ensure ESLint passes.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@web/src/hooks/use-knowledge-request.ts`:
- Around line 505-512: The query uses the raw knowledgeIds array in the queryKey
and in the payload (kbService.listTagByKnowledgeIds), causing cache duplication
when callers supply the same IDs in different orders; fix by creating a stable
sorted array (e.g., sortedKnowledgeIds = [...knowledgeIds].sort()) and use
sortedKnowledgeIds in the queryKey (replace usage of knowledgeIds) and when
building dataset_ids (use sortedKnowledgeIds.join(',')), keep the enabled check
(knowledgeIds.length > 0) the same, and run npm run lint in web/ to ensure
ESLint passes.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 7e038359-82c9-4ff4-9c79-f4aad8bd7630
📒 Files selected for processing (1)
web/src/hooks/use-knowledge-request.ts
See:
