]> granicus.if.org Git - neomutt/commitdiff
add nm_open_timeout
authorKarel Zak <kzak@redhat.com>
Mon, 16 Apr 2012 10:33:11 +0000 (12:33 +0200)
committerRichard Russon <rich@flatcap.org>
Mon, 4 Apr 2016 15:30:05 +0000 (16:30 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
README.notmuch
globals.h
init.h
mutt_notmuch.c

index 9d103cb7de98b42ea7147c09fb27a8ac0f1687fb..5647220574549008394b80e808a762e5150cb2a3 100644 (file)
@@ -115,6 +115,10 @@ notmuch support for mutt
       the sidebar. It's possible to toggle between virtual and normal folders by
       sidebar-toggle command.
 
+   notmuch_open_timeout = <seconds>
+
+      This option specifies timeout for Notmuch database. Default is 5 seconds.
+
    notmuch_default_uri = <uri>
 
       This variable specifies the default Notmuch database in format
index 276d5d468a82f501f070c91097ef406fadf90b26..95d9f122904bdebf1dd241497b747004a229772b 100644 (file)
--- a/globals.h
+++ b/globals.h
@@ -282,6 +282,7 @@ WHERE char *SmimeImportCertCommand;
 WHERE char *SmimeGetCertEmailCommand;
 
 #ifdef USE_NOTMUCH
+WHERE int NotmuchOpenTimeout;
 WHERE char *NotmuchDefaultUri;
 WHERE char *NotmuchUnreadTag;
 WHERE char *NotmuchHiddenTags;
diff --git a/init.h b/init.h
index 485acd150c7d6b976d30a5a152d125006bef5f8f..9145100ec233f36cd1483836a457c00118fc0618 100644 (file)
--- a/init.h
+++ b/init.h
@@ -1669,6 +1669,12 @@ struct option_t MuttVars[] = {
    */
 #endif
 #ifdef USE_NOTMUCH
+  { "nm_open_timeout", DT_NUM, R_NONE, UL &NotmuchOpenTimeout, 5 },
+  /*
+   ** .pp
+   ** This variable specifies the timeout for database open in seconds.
+   */
+
   { "nm_default_uri", DT_STR, R_NONE, UL &NotmuchDefaultUri, 0 },
   /*
    ** .pp
index e75b734705309010d0a4dcbe4d47b8f45887def1..a3378dcb9932d1c2019e7b8d3b31643a165b4f89 100644 (file)
@@ -342,6 +342,36 @@ static const char *get_db_filename(struct nm_ctxdata *data)
        return db_filename;
 }
 
+static notmuch_database_t *do_database_open(const char *filename,
+                                           int writable, int verbose)
+{
+       notmuch_database_t *db = NULL;
+       unsigned int ct = 0;
+
+       dprint(1, (debugfile, "nm: db open '%s' %s (timeout %d)\n", filename,
+                       writable ? "[WRITE]" : "[READ]", NotmuchOpenTimeout));
+       do {
+               db = notmuch_database_open(filename,
+                                       writable ? NOTMUCH_DATABASE_MODE_READ_WRITE :
+                                       NOTMUCH_DATABASE_MODE_READ_ONLY);
+               if (db || !NotmuchOpenTimeout || ct / 2 > NotmuchOpenTimeout)
+                       break;
+
+               if (verbose && ct && ct % 2 == 0)
+                       mutt_error(_("Waiting for notmuch DB... (%d sec)"), ct / 2);
+               usleep(500000);
+               ct++;
+       } while (1);
+
+       if (verbose) {
+               if (!db)
+                       mutt_error (_("Cannot open notmuch database: %s"), filename);
+               else if (ct > 1)
+                       mutt_clear_error();
+       }
+       return db;
+}
+
 static notmuch_database_t *get_db(struct nm_ctxdata *data, int writable)
 {
        if (!data)
@@ -349,20 +379,9 @@ static notmuch_database_t *get_db(struct nm_ctxdata *data, int writable)
        if (!data->db) {
                const char *db_filename = get_db_filename(data);
 
-               if (!db_filename)
-                       return NULL;
-
-               dprint(1, (debugfile, "nm: db open '%s' %s\n", db_filename,
-                                       writable ? "[WRITE]" : "[READ]"));
-
-               data->db = notmuch_database_open(db_filename,
-                               writable ? NOTMUCH_DATABASE_MODE_READ_WRITE :
-                               NOTMUCH_DATABASE_MODE_READ_ONLY);
-               if (!data->db)
-                       mutt_error (_("Cannot open notmuch database: %s"),
-                                       db_filename);
+               if (db_filename)
+                       data->db = do_database_open(db_filename, writable, TRUE);
        }
-
        return data->db;
 }
 
@@ -987,12 +1006,11 @@ int nm_nonctx_get_count(char *path, int *all, int *new)
                dflt = 1;
        }
 
-       dprint(1, (debugfile, "nm: count open DB\n"));
-       db = notmuch_database_open(db_filename, NOTMUCH_DATABASE_MODE_READ_ONLY);
-       if (!db) {
-               mutt_error (_("Cannot open notmuch database: %s"), db_filename);
+       /* don't be verbose about connection, as we're called from
+        * sidebar/buffy very often */
+       db = do_database_open(db_filename, FALSE, FALSE);
+       if (!db)
                goto done;
-       }
 
        /* all emails */
        if (all)