On 10 Feb 2016, at 17:30, Jorge Carling <gfinet...@hotmail.com> wrote: > > Dear all, > Lately I am working on PHP mail account management application. It has, among > others, Unread messages count column. > To get the number of unread messages, I execute "doveadm search" command for > each database row. > The search time for single account is about 0.03 seconds. Our system has > around 750 accounts, so the total loading time is currently around 20 seconds. > When setting up Dovecot, I made the user_query, which is also used to store > the message quota, and total number of messages stored in particular mailbox. > Is there a keyword that can be included in the user_query, or some other way > to maintain the unread messages count in the database? Maybe there is a way > to execute a script every time a message is received, or becomes read, or > unread.
It's much faster if you use: doveadm mailbox status -A unseen '*' Also if you enable mailbox_list_index=yes it's even faster. If you're using Maildir format you can also enable maildir_very_dirty_syncs=yes. If it's still not fast enough, it would require keeping the unseen counts in some kind of a database, but that would require writing a new plugin.