changeset 22371:e02a683b821c

virtual: Optimize mailbox_notify_changes() when there's only a single backend mailbox
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Wed, 19 Jul 2017 23:19:12 +0300
parents f51eb78b45f2
children e725baa58831
files src/plugins/virtual/virtual-storage.c
diffstat 1 files changed, 16 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/virtual/virtual-storage.c	Wed Jul 19 23:11:12 2017 +0300
+++ b/src/plugins/virtual/virtual-storage.c	Wed Jul 19 23:19:12 2017 +0300
@@ -711,14 +711,22 @@
 	}
 
 	array_foreach_modifiable(&mbox->backend_boxes, bboxp) {
-		/* we are already waiting for notifications */
-	        if ((*bboxp)->notify != NULL)
-			continue;
-		/* wait for notifications */
-		if (virtual_notify_start(*bboxp) == 0)
-			continue;
-		/* it did not work, so open the mailbox and use
-		   alternative method */
+		if (array_count(&mbox->backend_boxes) == 1 &&
+		    (*bboxp)->box->opened) {
+			/* There's only a single backend mailbox and its
+			   indexes are already opened. Might as well use the
+			   backend directly for notifications. */
+		} else {
+			/* we are already waiting for notifications */
+			if ((*bboxp)->notify != NULL)
+				continue;
+			/* wait for notifications */
+			if (virtual_notify_start(*bboxp) == 0)
+				continue;
+			/* it did not work, so open the mailbox and use
+			   alternative method */
+		}
+
 		if (!(*bboxp)->box->opened &&
 		    virtual_backend_box_open(mbox, *bboxp) < 0) {
 			/* we can't report error in here, so do it later */