From 12842bb3bee616d72e392acc830302afbee896e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20L=C3=BCtzner?= Date: Wed, 23 Sep 2026 19:12:09 +0200 Subject: [PATCH] fix(imap): index unread rows per folder for the post-sync recount Every folder sync ends with countUnseenForMailbox(), `mailbox_id = ? AND seen_at IS NULL`, which visited every row of the folder to test seen_at. A partial index on message(mailbox_id) WHERE seen_at IS NULL holds only the unread rows. Migration-only, like the table's other partial indexes. Co-Authored-By: Claude Opus 5.5 --- migrations/Version20260923101400.php | 38 ++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 migrations/Version20260923101400.php diff --git a/migrations/Version20260923101400.php b/migrations/Version20260923101400.php new file mode 100644 index 00000000..35274a92 --- /dev/null +++ b/migrations/Version20260923101400.php @@ -0,0 +1,38 @@ +addSql('CREATE INDEX idx_message_unseen_mailbox ON message (mailbox_id) WHERE seen_at IS NULL'); + } + + public function down(Schema $schema): void + { + $this->addSql('DROP INDEX idx_message_unseen_mailbox'); + } +}