store: save contacts more often
Use the new Contacts::dirty() so serialize/save the contacts whenever we commit a transaction. And some cosmetics.
This commit is contained in:
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** Copyright (C) 2021 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
** Copyright (C) 2021-2022 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||||
**
|
**
|
||||||
** This program is free software; you can redistribute it and/or modify it
|
** This program is free software; you can redistribute it and/or modify it
|
||||||
** under the terms of the GNU General Public License as published by the
|
** under the terms of the GNU General Public License as published by the
|
||||||
@ -102,7 +102,10 @@ add_synonym_for_prio(MuMsgPrio prio, Xapian::WritableDatabase* db)
|
|||||||
struct Store::Private {
|
struct Store::Private {
|
||||||
#define LOCKED std::lock_guard<std::mutex> l(lock_);
|
#define LOCKED std::lock_guard<std::mutex> l(lock_);
|
||||||
|
|
||||||
enum struct XapianOpts { ReadOnly, Open, CreateOverwrite, InMemory };
|
enum struct XapianOpts { ReadOnly,
|
||||||
|
Open,
|
||||||
|
CreateOverwrite,
|
||||||
|
InMemory };
|
||||||
|
|
||||||
Private(const std::string& path, bool readonly)
|
Private(const std::string& path, bool readonly)
|
||||||
: read_only_{readonly}, db_{make_xapian_db(path,
|
: read_only_{readonly}, db_{make_xapian_db(path,
|
||||||
@ -136,9 +139,6 @@ struct Store::Private {
|
|||||||
{
|
{
|
||||||
g_debug("closing store @ %s", mdata_.database_path.c_str());
|
g_debug("closing store @ %s", mdata_.database_path.c_str());
|
||||||
if (!read_only_) {
|
if (!read_only_) {
|
||||||
xapian_try([&] {
|
|
||||||
writable_db().set_metadata(ContactsKey, contacts_.serialize());
|
|
||||||
});
|
|
||||||
transaction_maybe_commit(true /*force*/);
|
transaction_maybe_commit(true /*force*/);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -201,6 +201,12 @@ struct Store::Private {
|
|||||||
return; // not supported or not in transaction
|
return; // not supported or not in transaction
|
||||||
|
|
||||||
if (force || transaction_size_ >= mdata_.batch_size) {
|
if (force || transaction_size_ >= mdata_.batch_size) {
|
||||||
|
if (contacts_.dirty()) {
|
||||||
|
xapian_try([&] {
|
||||||
|
writable_db().set_metadata(ContactsKey,
|
||||||
|
contacts_.serialize());
|
||||||
|
});
|
||||||
|
}
|
||||||
g_debug("committing transaction (n=%zu)", transaction_size_);
|
g_debug("committing transaction (n=%zu)", transaction_size_);
|
||||||
xapian_try([this] {
|
xapian_try([this] {
|
||||||
writable_db().commit_transaction();
|
writable_db().commit_transaction();
|
||||||
@ -494,7 +500,8 @@ Store::dirstamp(const std::string& path) const
|
|||||||
return epoch;
|
return epoch;
|
||||||
else
|
else
|
||||||
return static_cast<time_t>(strtoll(ts.c_str(), NULL, 16));
|
return static_cast<time_t>(strtoll(ts.c_str(), NULL, 16));
|
||||||
}, epoch);
|
},
|
||||||
|
epoch);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -763,7 +770,8 @@ add_terms_values_string_list(Xapian::Document& doc, MuMsg* msg, MuMsgFieldId mfi
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct PartData {
|
struct PartData {
|
||||||
PartData(Xapian::Document& doc, MuMsgFieldId mfid) : _doc(doc), _mfid(mfid) {}
|
PartData(Xapian::Document& doc, MuMsgFieldId mfid)
|
||||||
|
: _doc(doc), _mfid(mfid) {}
|
||||||
Xapian::Document _doc;
|
Xapian::Document _doc;
|
||||||
MuMsgFieldId _mfid;
|
MuMsgFieldId _mfid;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user