Compare commits

...
Author SHA1 Message Date
Sonarly Claude Code 5a1f3b1ed0 fix: lower Gmail message import batch size to avoid API rate limits
https://sonarly.com/issue/19834?type=bug

The hardcoded Gmail message import batch size of 400 fires 400+ concurrent API requests via `Promise.all`, exceeding Google's per-user concurrent connection limit (~250) and per-minute quota, causing every import cycle to fail with 429/403 errors.

Fix: Lowered `MESSAGING_GMAIL_USERS_MESSAGES_GET_BATCH_SIZE` from 400 to 50.

**Why 50:** The Gmail API has a per-user concurrent connection limit of ~250 and a per-minute quota of 15,000. With the previous value of 400, `GmailGetMessagesService.fetchMessages()` fires 400 concurrent `users.messages.get` calls via `Promise.all`. When `SELECTED_FOLDERS` policy is active, additional `users.threads.get` calls are fired for every unique thread, potentially doubling the concurrent request count to 800+. This consistently exceeds Google's limits.

The value 50 aligns with `GMAIL_BATCH_REQUEST_MAX_SIZE` (the HTTP batching size used by `@jrmdayn/googleapis-batcher`), meaning one HTTP batch per import cycle. This stays well within rate limits while still importing 50 messages per cycle (~3,000/hour given the 1-minute cron interval).

The existing test at `messaging-messages-import.service.spec.ts` uses the constant dynamically (`MESSAGING_GMAIL_USERS_MESSAGES_GET_BATCH_SIZE + 1`) so it automatically adapts to the new value.
2026-03-31 02:49:17 +00:00
@@ -1 +1 @@
export const MESSAGING_GMAIL_USERS_MESSAGES_GET_BATCH_SIZE = 400;
export const MESSAGING_GMAIL_USERS_MESSAGES_GET_BATCH_SIZE = 50;