@@ -20,6 +20,8 @@ type FileTextResult = { path: string; text: string; size: number; sha256: string
2020
2121const MAX_DIFF_FILE_BYTES = 200 * 1024
2222const MAX_LIST_LIMIT = 50
23+ const MAX_LIST_BULK_LIMIT = 200
24+ const MAX_LIST_TAKE = 1000
2325
2426export const getBySlug = query ( {
2527 args : { slug : v . string ( ) } ,
@@ -87,13 +89,14 @@ export const list = query({
8789 limit : v . optional ( v . number ( ) ) ,
8890 } ,
8991 handler : async ( ctx , args ) => {
90- const limit = args . limit ?? 24
92+ const limit = clampInt ( args . limit ?? 24 , 1 , MAX_LIST_BULK_LIMIT )
93+ const takeLimit = Math . min ( limit * 5 , MAX_LIST_TAKE )
9194 if ( args . batch ) {
9295 const entries = await ctx . db
9396 . query ( 'skills' )
9497 . withIndex ( 'by_batch' , ( q ) => q . eq ( 'batch' , args . batch ) )
9598 . order ( 'desc' )
96- . take ( limit * 5 )
99+ . take ( takeLimit )
97100 return entries . filter ( ( skill ) => ! skill . softDeletedAt ) . slice ( 0 , limit )
98101 }
99102 const ownerUserId = args . ownerUserId
@@ -102,13 +105,10 @@ export const list = query({
102105 . query ( 'skills' )
103106 . withIndex ( 'by_owner' , ( q ) => q . eq ( 'ownerUserId' , ownerUserId ) )
104107 . order ( 'desc' )
105- . take ( limit * 5 )
108+ . take ( takeLimit )
106109 return entries . filter ( ( skill ) => ! skill . softDeletedAt ) . slice ( 0 , limit )
107110 }
108- const entries = await ctx . db
109- . query ( 'skills' )
110- . order ( 'desc' )
111- . take ( limit * 5 )
111+ const entries = await ctx . db . query ( 'skills' ) . order ( 'desc' ) . take ( takeLimit )
112112 return entries . filter ( ( skill ) => ! skill . softDeletedAt ) . slice ( 0 , limit )
113113 } ,
114114} )
@@ -120,25 +120,23 @@ export const listWithLatest = query({
120120 limit : v . optional ( v . number ( ) ) ,
121121 } ,
122122 handler : async ( ctx , args ) => {
123- const limit = args . limit ?? 24
123+ const limit = clampInt ( args . limit ?? 24 , 1 , MAX_LIST_BULK_LIMIT )
124+ const takeLimit = Math . min ( limit * 5 , MAX_LIST_TAKE )
124125 let entries : Doc < 'skills' > [ ] = [ ]
125126 if ( args . batch ) {
126127 entries = await ctx . db
127128 . query ( 'skills' )
128129 . withIndex ( 'by_batch' , ( q ) => q . eq ( 'batch' , args . batch ) )
129130 . order ( 'desc' )
130- . take ( limit * 5 )
131+ . take ( takeLimit )
131132 } else if ( args . ownerUserId ) {
132133 entries = await ctx . db
133134 . query ( 'skills' )
134135 . withIndex ( 'by_owner' , ( q ) => q . eq ( 'ownerUserId' , args . ownerUserId ) )
135136 . order ( 'desc' )
136- . take ( limit * 5 )
137+ . take ( takeLimit )
137138 } else {
138- entries = await ctx . db
139- . query ( 'skills' )
140- . order ( 'desc' )
141- . take ( limit * 5 )
139+ entries = await ctx . db . query ( 'skills' ) . order ( 'desc' ) . take ( takeLimit )
142140 }
143141
144142 const filtered = entries . filter ( ( skill ) => ! skill . softDeletedAt ) . slice ( 0 , limit )
0 commit comments