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:
@ -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([&]{
|
||||
|
||||
Reference in New Issue
Block a user