perf(mailbox): scope the message-list query to the viewed folder in SQL
The mailbox list observed the entire `messages` table (observeSummaries, no WHERE/LIMIT), mapped every cached row to a domain Message, and filtered down to the visible account+folder in MailboxViewModel — so its cost scaled with the whole cache and re-ran on every write to `messages` (IDLE delivery, a flag toggle, a backfill page, any folder sync). On a 20k-row cache that is ~125 ms of work per unrelated write. Push the account/folder filter into SQL (observeFolderSummaries / observeUnifiedFolderSummaries, exposed via observeFolderMessages / observeUnifiedFolderMessages) and flatMapLatest the ViewModel over the selected account+folder. The only remaining client-side pass separates the normal list from an active search over the small folder-scoped set. Validated on an emulator against 1k/5k/20k-row caches (docs/perf/issue-86- profiling.md): the account-scoped query is ~1.5 ms flat (~80x faster at 20k) and is already served by the existing (accountId, folder, uid) index — so NO composite index and NO schema migration are added. The ticket's proposed (accountId, folder, inInbox, timestampMillis) index changes timing only within noise and isn't even preferred by SQLite's planner. The unified "All inboxes" view stays an O(N) folder scan (still 5.6x better) and is a follow-up for paging; IMAP latency on folder open is a separate, unmeasured concern. Closes #86 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -86,7 +86,11 @@ class FakeMailRepository(
|
||||
val movedToFolder = mutableListOf<Pair<List<String>, String>>()
|
||||
val replyDrafts = mutableListOf<Pair<String, ReplyMode>>()
|
||||
|
||||
override fun observeMessages(): Flow<List<Message>> = flowOf(messages)
|
||||
override fun observeFolderMessages(accountId: String, folder: String): Flow<List<Message>> =
|
||||
flowOf(messages.filter { it.accountId == accountId && it.folder == folder })
|
||||
|
||||
override fun observeUnifiedFolderMessages(folder: String): Flow<List<Message>> =
|
||||
flowOf(messages.filter { it.folder == folder })
|
||||
|
||||
override fun observeFolders(accountId: String): Flow<List<Folder>> = flowOf(
|
||||
folders.filter {
|
||||
|
||||
Reference in New Issue
Block a user