File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -83,7 +83,16 @@ class CodeManager {
8383 if ( codes . length === 0 || discordIds . length === 0 ) return new Map ( ) ;
8484 // Budget per query: codes.length (inArray) + 3 (status OR literals) + chunk size (discordIds inArray).
8585 const SQLITE_MAX_PARAMS = 999 ;
86- const chunkSize = Math . max ( 1 , SQLITE_MAX_PARAMS - codes . length - 3 ) ;
86+ const STATUS_PARAM_COUNT = 3 ;
87+ const MIN_DISCORD_ID_CHUNK_SIZE = 1 ;
88+ const maxCodesPerQuery = SQLITE_MAX_PARAMS - STATUS_PARAM_COUNT - MIN_DISCORD_ID_CHUNK_SIZE ;
89+ if ( codes . length > maxCodesPerQuery ) {
90+ throw new Error (
91+ `Too many codes provided to getRedeemedCodesByUsers: ${ codes . length } . ` +
92+ `This query supports at most ${ maxCodesPerQuery } codes per call within SQLite's parameter limit of ${ SQLITE_MAX_PARAMS } .`
93+ ) ;
94+ }
95+ const chunkSize = SQLITE_MAX_PARAMS - codes . length - STATUS_PARAM_COUNT ;
8796 const result = new Map < string , Set < string > > ( ) ;
8897 for ( let i = 0 ; i < discordIds . length ; i += chunkSize ) {
8998 const chunk = discordIds . slice ( i , i + chunkSize ) ;
You can’t perform that action at this time.
0 commit comments