@@ -89,13 +89,20 @@ subscriptionRouter.post(
8989 } ) ;
9090 }
9191
92- // Get email addresses for all subscribed users
92+ // need to batch to avoid URL length limits
9393 const userIds = subscriptions . map ( ( sub ) => sub . userId ) ;
94- const { data : users } = await SupabaseDB . AUTH_INFO . select ( "email" )
95- . in ( "userId" , userIds )
96- . throwOnError ( ) ;
94+ const BATCH_SIZE = 100 ;
95+ const emailAddresses : string [ ] = [ ] ;
96+
97+ for ( let i = 0 ; i < userIds . length ; i += BATCH_SIZE ) {
98+ const batch = userIds . slice ( i , i + BATCH_SIZE ) ;
99+ const { data : users } = await SupabaseDB . AUTH_INFO . select ( "email" )
100+ . in ( "userId" , batch )
101+ . throwOnError ( ) ;
97102
98- const emailAddresses = users ?. map ( ( user ) => user . email ) || [ ] ;
103+ const batchEmails = users ?. map ( ( user ) => user . email ) || [ ] ;
104+ emailAddresses . push ( ...batchEmails ) ;
105+ }
99106
100107 const sendEmailCommand = new SendEmailCommand ( {
101108 FromEmailAddress : Config . FROM_EMAIL_ADDRESS ?? "" ,
@@ -168,13 +175,20 @@ subscriptionRouter.get(
168175 . json ( { error : "No subscribers found for this mailing list." } ) ;
169176 }
170177
171- // Get email addresses for all subscribed users
178+ // Get email addresses for all subscribed users (batch to avoid URL length limits)
172179 const userIds = subscriptions . map ( ( sub ) => sub . userId ) ;
173- const { data : users } = await SupabaseDB . AUTH_INFO . select ( "email" )
174- . in ( "userId" , userIds )
175- . throwOnError ( ) ;
180+ const BATCH_SIZE = 100 ; // Process in smaller batches
181+ const emailAddresses : string [ ] = [ ] ;
182+
183+ for ( let i = 0 ; i < userIds . length ; i += BATCH_SIZE ) {
184+ const batch = userIds . slice ( i , i + BATCH_SIZE ) ;
185+ const { data : users } = await SupabaseDB . AUTH_INFO . select ( "email" )
186+ . in ( "userId" , batch )
187+ . throwOnError ( ) ;
176188
177- const emailAddresses = users ?. map ( ( user ) => user . email ) || [ ] ;
189+ const batchEmails = users ?. map ( ( user ) => user . email ) || [ ] ;
190+ emailAddresses . push ( ...batchEmails ) ;
191+ }
178192
179193 return res . status ( StatusCodes . OK ) . json ( emailAddresses ) ;
180194 }
0 commit comments