Skip to content

Commit b3e194c

Browse files
BigMichi1Copilot
andauthored
Potential fix for pull request finding
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 0c487ff commit b3e194c

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

src/bot/database/codeManager.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff 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);

0 commit comments

Comments
 (0)