Skip to content

perf(get_emails): batch fetch all emails in single IMAP lock#2

Open
harcek wants to merge 1 commit into
feat/search-controlsfrom
perf/batch-email-fetch
Open

perf(get_emails): batch fetch all emails in single IMAP lock#2
harcek wants to merge 1 commit into
feat/search-controlsfrom
perf/batch-email-fetch

Conversation

@harcek

@harcek harcek commented Apr 26, 2026

Copy link
Copy Markdown
Owner

The upstream get_emails used Promise.allSettled(ids.map(async (id) => ...)), which opened a separate IMAP mailbox lock per email — effectively N sequential round-trips.

New getEmailsBatch() in imap.service.ts:

  • Opens the mailbox once with a single getMailboxLock()
  • Fetches all requested UIDs in one client.fetch(range, ...) call
  • Collects results into a Map, returns settled results in original order
  • Errors on individual messages are isolated; the rest still resolve

Also raised the per-call limit from 20 → 50 to match the new efficiency.

Depends on #1 (feat/search-controls → harcek/email-mcp).

Tested against Gmail and other IMAP providers. No regressions on existing tools.

Previously get_emails called getEmail() N times, each opening and releasing
the mailbox lock individually (N round trips). getEmailsBatch() opens the
mailbox once, issues a single FETCH for all UIDs, and collects results in
a Map before releasing the lock — dramatically faster for large batches.

Max IDs increased from 20 → 50 to take advantage of the efficiency gain.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant