@@ -23,6 +23,7 @@ export const conversationGroup = new Elysia().use(authPlugin).group("/conversati
2323 . get (
2424 "" ,
2525 async ( { locals, query } ) => {
26+ const pageSize = CONV_NUM_PER_PAGE ;
2627 const convs = await collections . conversations
2728 . find ( authCondition ( locals ) )
2829 . project < Pick < Conversation , "_id" | "title" | "updatedAt" | "model" > > ( {
@@ -31,15 +32,12 @@ export const conversationGroup = new Elysia().use(authPlugin).group("/conversati
3132 model : 1 ,
3233 } )
3334 . sort ( { updatedAt : - 1 } )
34- . skip ( ( query . p ?? 0 ) * CONV_NUM_PER_PAGE )
35- . limit ( CONV_NUM_PER_PAGE )
35+ . skip ( ( query . p ?? 0 ) * pageSize )
36+ . limit ( pageSize + 1 ) // fetch one extra to detect next page
3637 . toArray ( ) ;
3738
38- const nConversations = await collections . conversations . countDocuments (
39- authCondition ( locals )
40- ) ;
41-
42- const res = convs . map ( ( conv ) => ( {
39+ const hasMore = convs . length > pageSize ;
40+ const res = ( hasMore ? convs . slice ( 0 , pageSize ) : convs ) . map ( ( conv ) => ( {
4341 _id : conv . _id ,
4442 id : conv . _id , // legacy param iOS
4543 title : conv . title ,
@@ -48,7 +46,7 @@ export const conversationGroup = new Elysia().use(authPlugin).group("/conversati
4846 modelId : conv . model , // legacy param iOS
4947 } ) ) ;
5048
51- return { conversations : res , nConversations } ;
49+ return { conversations : res , hasMore } ;
5250 } ,
5351 {
5452 query : t . Object ( {
0 commit comments