From f01360ae9fefc488fe3e439884fc1499c7bdcdcb Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Sun, 4 Aug 2024 22:27:17 +0300 Subject: [PATCH] lib: commit to disk after indexing --- lib/mu-indexer.cc | 2 ++ lib/mu-xapian-db.hh | 21 +++++++++++---------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/mu-indexer.cc b/lib/mu-indexer.cc index 283a11b8..ec4ef013 100644 --- a/lib/mu-indexer.cc +++ b/lib/mu-indexer.cc @@ -363,6 +363,8 @@ Indexer::Private::scan_worker() } completed_ = ::time({}); + // attempt to commit to disk. + store_.xapian_db().request_commit(true); store_.config().set(completed_); state_.change_to(IndexState::Idle); } diff --git a/lib/mu-xapian-db.hh b/lib/mu-xapian-db.hh index 66739e58..27921b77 100644 --- a/lib/mu-xapian-db.hh +++ b/lib/mu-xapian-db.hh @@ -445,8 +445,7 @@ public: /** - * Explicitly request the Xapian DB to be committed to disk. This won't - * do anything when not in a transaction. + * Explicitly request the Xapian DB to be committed to disk * * @param force whether to force-commit */ @@ -464,21 +463,23 @@ public: private: /** - * To be called after all changes, with DB_LOCKED held. + * To be called with DB_LOCKED held. */ void request_commit(Xapian::WritableDatabase& db, bool force) { - // in transaction-mode and enough changes, commit them - if (!in_transaction()) - return; if ((++changes_ < batch_size_) && !force) return; xapian_try([&]{ - mu_debug("committing transaction with {} changes; " - "forced={}", changes_, force ? "yes" : "no"); - db.commit_transaction(); + mu_debug("committing {} changes; transaction={}; " + "forced={}", changes_, + in_transaction() ? "yes" : "no", + force ? "yes" : "no"); + if (in_transaction()) { + db.commit_transaction(); + in_transaction_ = {}; + } db.commit(); changes_ = 0; - in_transaction_ = {}; + }); }