yangdx commited on
Commit
681a00f
·
1 Parent(s): 9c57c96

Optimize document sorting with useCallback

Browse files

- Memoize sortDocuments function
- Add dependencies to useCallback
- Improve performance

lightrag_webui/src/features/DocumentManager.tsx CHANGED
@@ -167,7 +167,7 @@ export default function DocumentManager() {
167
  }
168
 
169
  // Sort documents based on current sort field and direction
170
- const sortDocuments = (documents: DocStatusResponse[]) => {
171
  return [...documents].sort((a, b) => {
172
  let valueA, valueB;
173
 
@@ -194,7 +194,7 @@ export default function DocumentManager() {
194
  return sortMultiplier * (valueA > valueB ? 1 : valueA < valueB ? -1 : 0);
195
  }
196
  });
197
- }
198
 
199
  const filteredAndSortedDocs = useMemo(() => {
200
  if (!docs) return null;
@@ -223,7 +223,7 @@ export default function DocumentManager() {
223
  }, {} as DocsStatusesResponse['statuses']);
224
 
225
  return { ...filteredDocs, statuses: sortedStatuses };
226
- }, [docs, sortField, sortDirection, statusFilter]);
227
 
228
  // Calculate document counts for each status
229
  const documentCounts = useMemo(() => {
 
167
  }
168
 
169
  // Sort documents based on current sort field and direction
170
+ const sortDocuments = useCallback((documents: DocStatusResponse[]) => {
171
  return [...documents].sort((a, b) => {
172
  let valueA, valueB;
173
 
 
194
  return sortMultiplier * (valueA > valueB ? 1 : valueA < valueB ? -1 : 0);
195
  }
196
  });
197
+ }, [sortField, sortDirection, showFileName]);
198
 
199
  const filteredAndSortedDocs = useMemo(() => {
200
  if (!docs) return null;
 
223
  }, {} as DocsStatusesResponse['statuses']);
224
 
225
  return { ...filteredDocs, statuses: sortedStatuses };
226
+ }, [docs, sortField, sortDirection, statusFilter, sortDocuments]);
227
 
228
  // Calculate document counts for each status
229
  const documentCounts = useMemo(() => {