X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=lib%2Fdatabase.cc;h=31794900a392194e641675b2ec15df3214b075f8;hp=aed053884108fdcf3ce30d94edc78fc77249c92a;hb=e2a3e5fa51122efb0f5ac836e536881d97deef1a;hpb=8aabddb043d6bf5bd8a19884b3c456ba9d4634cb diff --git a/lib/database.cc b/lib/database.cc index aed05388..31794900 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -1134,13 +1134,21 @@ notmuch_database_end_atomic (notmuch_database_t *notmuch) db = notmuch->writable_xapian_db; try { db->commit_transaction (); - - /* This is a hack for testing. Xapian never flushes on a - * non-flushed commit, even if the flush threshold is 1. - * However, we rely on flushing to test atomicity. */ + notmuch->transaction_count++; + + /* Xapian never flushes on a non-flushed commit, even if the + * flush threshold is 1. However, we rely on flushing to test + * atomicity. On the other hand, we can't straight replace + * XAPIAN_FLUSH_THRESHOLD with our autocommit counter, because + * the former also applies outside notmuch atomic + * commits. Hence the follow complicated test */ const char *thresh = getenv ("XAPIAN_FLUSH_THRESHOLD"); - if (thresh && atoi (thresh) == 1) + if ((notmuch->transaction_threshold > 0 && + notmuch->transaction_count >= notmuch->transaction_threshold) || + (thresh && atoi (thresh) == 1)) { db->commit (); + notmuch->transaction_count = 0; + } } catch (const Xapian::Error &error) { _notmuch_database_log (notmuch, "A Xapian exception occurred committing transaction: %s.\n", error.get_msg ().c_str ());