Skip to content

Commit

Permalink
lib: commit to disk after indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
djcb committed Aug 4, 2024
1 parent b825e39 commit f01360a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
2 changes: 2 additions & 0 deletions lib/mu-indexer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,8 @@ Indexer::Private::scan_worker()
}

completed_ = ::time({});
// attempt to commit to disk.
store_.xapian_db().request_commit(true);
store_.config().set<Mu::Config::Id::LastIndex>(completed_);
state_.change_to(IndexState::Idle);
}
Expand Down
21 changes: 11 additions & 10 deletions lib/mu-xapian-db.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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_ = {};

});
}

Expand Down

0 comments on commit f01360a

Please sign in to comment.