Преглед изворни кода

Update pagination limit for recent threads to 20 in validation and default settings

Shun Miyazawa пре 9 месеци
родитељ
комит
17c5746312

+ 4 - 12
apps/app/src/features/openai/client/stores/thread.tsx

@@ -1,4 +1,4 @@
-import { type SWRResponse, type SWRConfiguration } from 'swr';
+import { type SWRResponse } from 'swr';
 import useSWRImmutable from 'swr/immutable';
 import useSWRInfinite from 'swr/infinite';
 import type { SWRInfiniteResponse } from 'swr/infinite';
@@ -28,32 +28,24 @@ export const useSWRMUTxThreads = (aiAssistantId?: string): SWRMutationResponse<I
 };
 
 
-// Helper function to generate key for pagination
-const getRecentThreadsKey = (
-    pageIndex: number,
-    previousPageData: IThreadRelationPaginate | null,
-): [string, number, number] | null => {
-  // If no more data, return null to stop fetching
+const getRecentThreadsKey = (pageIndex: number, previousPageData: IThreadRelationPaginate | null): [string, number, number] | null => {
   if (previousPageData && !previousPageData.paginateResult.hasNextPage) {
     return null;
   }
 
-  const PER_PAGE = 10; // Match the server's default limit
-  const page = pageIndex + 1; // Convert zero-based index to one-based page
+  const PER_PAGE = 20;
+  const page = pageIndex + 1;
 
   return ['/openai/threads/recent', page, PER_PAGE];
 };
 
 
 export const useSWRINFxRecentThreads = (
-    config?: SWRConfiguration,
 ): SWRInfiniteResponse<IThreadRelationPaginate, Error> => {
-  const PER_PAGE = 20;
   return useSWRInfinite(
     (pageIndex, previousPageData) => getRecentThreadsKey(pageIndex, previousPageData),
     ([endpoint, page, limit]) => apiv3Get<IThreadRelationPaginate>(endpoint, { page, limit }).then(response => response.data),
     {
-      ...config,
       revalidateFirstPage: false,
       revalidateAll: true,
     },

+ 2 - 2
apps/app/src/features/openai/server/routes/get-recent-threads.ts

@@ -36,7 +36,7 @@ export const getRecentThreadsFactory: GetRecentThreadsFactory = (crowi) => {
   const validator: ValidationChain[] = [
     query('page').optional().isInt().withMessage('page must be a positive integer'),
     query('page').toInt(),
-    query('limit').optional().isInt({ min: 1, max: 10 }).withMessage('limit must be an integer between 1 and 10'),
+    query('limit').optional().isInt({ min: 1, max: 20 }).withMessage('limit must be an integer between 1 and 20'),
     query('limit').toInt(),
   ];
 
@@ -57,7 +57,7 @@ export const getRecentThreadsFactory: GetRecentThreadsFactory = (crowi) => {
           },
           {
             page: req.query.page ?? 1,
-            limit: req.query.limit ?? 10,
+            limit: req.query.limit ?? 20,
             sort: { updatedAt: -1 },
             populate: 'aiAssistant',
           },