lib: commit to disk after indexing

This commit is contained in:
Dirk-Jan C. Binnema
2024-08-04 22:27:17 +03:00
parent b825e39fdc
commit f01360ae9f
2 changed files with 13 additions and 10 deletions

View File

@ -363,6 +363,8 @@ Indexer::Private::scan_worker()
} }
completed_ = ::time({}); completed_ = ::time({});
// attempt to commit to disk.
store_.xapian_db().request_commit(true);
store_.config().set<Mu::Config::Id::LastIndex>(completed_); store_.config().set<Mu::Config::Id::LastIndex>(completed_);
state_.change_to(IndexState::Idle); state_.change_to(IndexState::Idle);
} }

View File

@ -445,8 +445,7 @@ public:
/** /**
* Explicitly request the Xapian DB to be committed to disk. This won't * Explicitly request the Xapian DB to be committed to disk
* do anything when not in a transaction.
* *
* @param force whether to force-commit * @param force whether to force-commit
*/ */
@ -464,21 +463,23 @@ public:
private: 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) { 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) if ((++changes_ < batch_size_) && !force)
return; return;
xapian_try([&]{ xapian_try([&]{
mu_debug("committing transaction with {} changes; " mu_debug("committing {} changes; transaction={}; "
"forced={}", changes_, force ? "yes" : "no"); "forced={}", changes_,
db.commit_transaction(); in_transaction() ? "yes" : "no",
force ? "yes" : "no");
if (in_transaction()) {
db.commit_transaction();
in_transaction_ = {};
}
db.commit(); db.commit();
changes_ = 0; changes_ = 0;
in_transaction_ = {};
}); });
} }