Skip to content

Return Mail search pages when the scope count times out - #8

Merged
mattt merged 2 commits into
mainfrom
mattt/best-effort-scope-count
Oct 27, 2026
Merged

mattt merged 2 commits into
mainfrom
mattt/best-effort-scope-count

Conversation

@mattt

@mattt mattt commented Oct 27, 2026

Copy link
Copy Markdown
Owner

A Mail search also counts the indexed messages in the selected mailbox, or in the whole store when no mailbox is selected, without the search filters (mattt/iMCP#312). The count runs after the page, in the same read transaction. On a large Mail store, it can pass the default 100 ms statement limit, and the search throws queryTimedOut and discards the page.

This PR makes the count best effort. When counting passes the statement or snapshot time limit, search returns the page and its next cursor with a nil indexedMessageCount. Other errors and cancellation still propagate. The count also leaves out the joins to subjects and addresses, which can't change it.

SearchResult.indexedMessageCount is now Int?, which is a source-breaking change.

@mattt
mattt merged commit edccf6c into main Oct 27, 2026
4 checks passed
@mattt
mattt deleted the mattt/best-effort-scope-count branch October 27, 2026 12:03
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