store: add 'add_document' optimization, use it

*Usually* we need Xapian's replace_document() API, but when we know a
document (message) is completely new, we can use the faster
add_document(). That is the case with the initial (re)indexing, when
start with an empty database.

Also a few smaller cleanups.
This commit is contained in:
Dirk-Jan C. Binnema
2023-07-25 23:52:22 +03:00
parent 4d8ba5f579
commit 4c0b7db3d8
5 changed files with 89 additions and 67 deletions

View File

@ -281,6 +281,22 @@ public:
DB_LOCKED; return db().term_exists(term);}, false);
}
/**
* Add a new document to the database
*
* @param doc a document (message)
*
* @return new docid or 0
*/
Xapian::docid add_document(const Xapian::Document& doc) {
return xapian_try([&]{
DB_LOCKED;
auto&& id= wdb().add_document(doc);
set_timestamp(MetadataIface::last_change_key);
return id;
}, 0);
}
/**
* Replace document in database
*
@ -288,7 +304,7 @@ public:
* @param id docid
* @param doc replacement document
*
* @return new docid or nothing.
* @return new docid or 0
*/
Xapian::docid replace_document(const std::string& term, const Xapian::Document& doc) {
return xapian_try([&]{