From 38201182468ee2d8a289e2d6c50ece7bdf9e12ca Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Sun, 13 Feb 2022 14:52:41 +0200 Subject: [PATCH] store: rename "metadata" into "properties" properties are the constant (for the duration) values for a store; metadata may change, so reserve that name for that. --- guile/mu-guile.cc | 4 +- lib/index/mu-indexer.cc | 10 ++--- lib/mu-server.cc | 6 +-- lib/mu-store.cc | 78 ++++++++++++++++++-------------------- lib/mu-store.hh | 9 +++-- lib/tests/test-mu-store.cc | 4 +- mu/mu-cmd-index.cc | 6 +-- mu/mu-cmd-server.cc | 4 +- mu/mu-cmd.cc | 14 +++---- 9 files changed, 67 insertions(+), 68 deletions(-) diff --git a/guile/mu-guile.cc b/guile/mu-guile.cc index 077b8911..b916f273 100644 --- a/guile/mu-guile.cc +++ b/guile/mu-guile.cc @@ -85,9 +85,9 @@ try { StoreSingleton = std::make_unique(mu_runtime_path(MU_RUNTIME_PATH_XAPIANDB)); g_debug("mu-guile: opened store @ %s (n=%zu); maildir: %s", - StoreSingleton->metadata().database_path.c_str(), + StoreSingleton->properties().database_path.c_str(), StoreSingleton->size(), - StoreSingleton->metadata().root_maildir.c_str()); + StoreSingleton->properties().root_maildir.c_str()); return TRUE; diff --git a/lib/index/mu-indexer.cc b/lib/index/mu-indexer.cc index 9790ff36..92d73dc4 100644 --- a/lib/index/mu-indexer.cc +++ b/lib/index/mu-indexer.cc @@ -79,15 +79,15 @@ private: struct Indexer::Private { Private(Mu::Store& store) - : store_{store}, scanner_{store_.metadata().root_maildir, + : store_{store}, scanner_{store_.properties().root_maildir, [this](auto&& path, auto&& statbuf, auto&& info) { return handler(path, statbuf, info); }}, - max_message_size_{store_.metadata().max_message_size} + max_message_size_{store_.properties().max_message_size} { g_message("created indexer for %s -> %s (batch-size: %zu)", - store.metadata().root_maildir.c_str(), - store.metadata().database_path.c_str(), store.metadata().batch_size); + store.properties().root_maildir.c_str(), + store.properties().database_path.c_str(), store.properties().batch_size); } ~Private() @@ -379,7 +379,7 @@ Indexer::~Indexer() = default; bool Indexer::start(const Indexer::Config& conf) { - const auto mdir{priv_->store_.metadata().root_maildir}; + const auto mdir{priv_->store_.properties().root_maildir}; if (G_UNLIKELY(access(mdir.c_str(), R_OK) != 0)) { g_critical("'%s' is not readable: %s", mdir.c_str(), g_strerror(errno)); return false; diff --git a/lib/mu-server.cc b/lib/mu-server.cc index 324a36b8..d76945b6 100644 --- a/lib/mu-server.cc +++ b/lib/mu-server.cc @@ -983,7 +983,7 @@ Server::Private::ping_handler(const Parameters& params) } Sexp::List addrs; - for (auto&& addr : store().metadata().personal_addresses) + for (auto&& addr : store().properties().personal_addresses) addrs.add(Sexp::make_string(addr)); Sexp::List lst; @@ -992,8 +992,8 @@ Server::Private::ping_handler(const Parameters& params) Sexp::List proplst; proplst.add_prop(":version", Sexp::make_string(VERSION)); proplst.add_prop(":personal-addresses", Sexp::make_list(std::move(addrs))); - proplst.add_prop(":database-path", Sexp::make_string(store().metadata().database_path)); - proplst.add_prop(":root-maildir", Sexp::make_string(store().metadata().root_maildir)); + proplst.add_prop(":database-path", Sexp::make_string(store().properties().database_path)); + proplst.add_prop(":root-maildir", Sexp::make_string(store().properties().root_maildir)); proplst.add_prop(":doccount", Sexp::make_number(storecount)); proplst.add_prop(":queries", Sexp::make_list(std::move(qresults))); diff --git a/lib/mu-store.cc b/lib/mu-store.cc index ed2371f1..2a406262 100644 --- a/lib/mu-store.cc +++ b/lib/mu-store.cc @@ -52,6 +52,7 @@ constexpr auto RootMaildirKey = "maildir"; // XXX: make this 'root-maildir constexpr auto ContactsKey = "contacts"; constexpr auto PersonalAddressesKey = "personal-addresses"; constexpr auto CreatedKey = "created"; +constexpr auto LastIndexKey = "last-index"; /* time of last index */ constexpr auto BatchSizeKey = "batch-size"; constexpr auto DefaultBatchSize = 250'000U; @@ -88,27 +89,24 @@ add_synonym_for_flag(MuFlags flag, Xapian::WritableDatabase* db) } struct Store::Private { - enum struct XapianOpts { ReadOnly, - Open, - CreateOverwrite, - InMemory }; + enum struct XapianOpts { ReadOnly, Open, CreateOverwrite, InMemory }; Private(const std::string& path, bool readonly) : read_only_{readonly}, db_{make_xapian_db(path, read_only_ ? XapianOpts::ReadOnly : XapianOpts::Open)}, - mdata_{make_metadata(path)}, contacts_{db().get_metadata(ContactsKey), - mdata_.personal_addresses} + properties_{make_properties(path)}, contacts_{db().get_metadata(ContactsKey), + properties_.personal_addresses} { } - Private(const std::string& path, - const std::string& root_maildir, - const StringVec& personal_addresses, + Private(const std::string& path, + const std::string& root_maildir, + const StringVec& personal_addresses, const Store::Config& conf) : read_only_{false}, db_{make_xapian_db(path, XapianOpts::CreateOverwrite)}, - mdata_{init_metadata(conf, path, root_maildir, personal_addresses)}, - contacts_{"", mdata_.personal_addresses} + properties_{init_metadata(conf, path, root_maildir, personal_addresses)}, + contacts_{"", properties_.personal_addresses} { } @@ -116,14 +114,14 @@ struct Store::Private { const StringVec& personal_addresses, const Store::Config& conf) : read_only_{false}, db_{make_xapian_db("", XapianOpts::InMemory)}, - mdata_{init_metadata(conf, "", root_maildir, personal_addresses)}, - contacts_{"", mdata_.personal_addresses} + properties_{init_metadata(conf, "", root_maildir, personal_addresses)}, + contacts_{"", properties_.personal_addresses} { } ~Private() try { - g_debug("closing store @ %s", mdata_.database_path.c_str()); + g_debug("closing store @ %s", properties_.database_path.c_str()); if (!read_only_) { transaction_maybe_commit(true /*force*/); } @@ -171,7 +169,7 @@ struct Store::Private { // If not started yet, start a transaction. Otherwise, just update the transaction size. void transaction_inc() noexcept { - if (mdata_.in_memory) + if (properties_.in_memory) return; // not supported if (transaction_size_ == 0) { @@ -185,10 +183,10 @@ struct Store::Private { // filled up a batch, or with force. void transaction_maybe_commit(bool force = false) noexcept { - if (mdata_.in_memory || transaction_size_ == 0) + if (properties_.in_memory || transaction_size_ == 0) return; // not supported or not in transaction - if (force || transaction_size_ >= mdata_.batch_size) { + if (force || transaction_size_ >= properties_.batch_size) { if (contacts_.dirty()) { xapian_try([&] { writable_db().set_metadata(ContactsKey, @@ -227,26 +225,24 @@ struct Store::Private { return (time_t)atoll(db().get_metadata(key).c_str()); } - Store::Metadata make_metadata(const std::string& db_path) + Store::Properties make_properties(const std::string& db_path) { - Store::Metadata mdata; + Store::Properties props; - mdata.database_path = db_path; - mdata.schema_version = db().get_metadata(SchemaVersionKey); - mdata.created = ::atoll(db().get_metadata(CreatedKey).c_str()); - mdata.read_only = read_only_; + props.database_path = db_path; + props.schema_version = db().get_metadata(SchemaVersionKey); + props.created = ::atoll(db().get_metadata(CreatedKey).c_str()); + props.read_only = read_only_; + props.batch_size = ::atoll(db().get_metadata(BatchSizeKey).c_str()); + props.max_message_size = ::atoll(db().get_metadata(MaxMessageSizeKey).c_str()); + props.in_memory = db_path.empty(); + props.root_maildir = db().get_metadata(RootMaildirKey); + props.personal_addresses = Mu::split(db().get_metadata(PersonalAddressesKey), ","); - mdata.batch_size = ::atoll(db().get_metadata(BatchSizeKey).c_str()); - mdata.max_message_size = ::atoll(db().get_metadata(MaxMessageSizeKey).c_str()); - mdata.in_memory = db_path.empty(); - - mdata.root_maildir = db().get_metadata(RootMaildirKey); - mdata.personal_addresses = Mu::split(db().get_metadata(PersonalAddressesKey), ","); - - return mdata; + return props; } - Store::Metadata init_metadata(const Store::Config& conf, + Store::Properties init_metadata(const Store::Config& conf, const std::string& path, const std::string& root_maildir, const StringVec& personal_addresses) @@ -273,7 +269,7 @@ struct Store::Private { } writable_db().set_metadata(PersonalAddressesKey, addrs); - return make_metadata(path); + return make_properties(path); } Xapian::docid add_or_update_msg(Xapian::docid docid, MuMsg* msg); @@ -286,7 +282,7 @@ struct Store::Private { const bool read_only_{}; std::unique_ptr db_; - const Store::Metadata mdata_; + const Store::Properties properties_; Contacts contacts_; std::unique_ptr indexer_; @@ -313,12 +309,12 @@ get_uid_term(const char* path) Store::Store(const std::string& path, bool readonly) : priv_{std::make_unique(path, readonly)} { - if (metadata().schema_version != ExpectedSchemaVersion) + if (properties().schema_version != ExpectedSchemaVersion) throw Mu::Error(Error::Code::SchemaMismatch, "expected schema-version %s, but got %s; " "please use 'mu init'", ExpectedSchemaVersion, - metadata().schema_version.c_str()); + properties().schema_version.c_str()); } Store::Store(const std::string& path, @@ -336,10 +332,10 @@ Store::Store(const std::string& maildir, const StringVec& personal_addresses, co Store::~Store() = default; -const Store::Metadata& -Store::metadata() const +const Store::Properties& +Store::properties() const { - return priv_->mdata_; + return priv_->properties_; } const Contacts& @@ -365,7 +361,7 @@ Store::indexer() { std::lock_guard guard{priv_->lock_}; - if (metadata().read_only) + if (properties().read_only) throw Error{Error::Code::Store, "no indexer for read-only store"}; else if (!priv_->indexer_) priv_->indexer_ = std::make_unique(*this); @@ -419,7 +415,7 @@ Store::add_message(const std::string& path, bool use_transaction) std::lock_guard guard{priv_->lock_}; GError* gerr{}; - const auto maildir{maildir_from_path(metadata().root_maildir, path)}; + const auto maildir{maildir_from_path(properties().root_maildir, path)}; auto msg{mu_msg_new_from_file(path.c_str(), maildir.c_str(), &gerr)}; if (G_UNLIKELY(!msg)) throw Error{Error::Code::Message, diff --git a/lib/mu-store.hh b/lib/mu-store.hh index 6d72c35d..2b67b991 100644 --- a/lib/mu-store.hh +++ b/lib/mu-store.hh @@ -86,7 +86,10 @@ public: */ ~Store(); - struct Metadata { + /** + * Store properties + */ + struct Properties { std::string database_path; /**< Full path to the Xapian database */ std::string schema_version; /**< Database schema version */ std::time_t created; /**< database creation time */ @@ -102,11 +105,11 @@ public: }; /** - * Get metadata about this store. + * Get properties about this store. * * @return the metadata */ - const Metadata& metadata() const; + const Properties& properties() const; /** * Get the Contacts object for this store * diff --git a/lib/tests/test-mu-store.cc b/lib/tests/test-mu-store.cc index 07794211..2f4f3e20 100644 --- a/lib/tests/test-mu-store.cc +++ b/lib/tests/test-mu-store.cc @@ -43,7 +43,7 @@ test_store_ctor_dtor() g_assert_true(store.empty()); g_assert_cmpuint(0, ==, store.size()); - g_assert_cmpstr(MU_STORE_SCHEMA_VERSION, ==, store.metadata().schema_version.c_str()); + g_assert_cmpstr(MU_STORE_SCHEMA_VERSION, ==, store.properties().schema_version.c_str()); } static void @@ -84,7 +84,7 @@ test_store_add_count_remove_in_memory() { Mu::Store store{MuTestMaildir, {}, {}}; - g_assert_true(store.metadata().in_memory); + g_assert_true(store.properties().in_memory); const auto id1 = store.add_message(MuTestMaildir + "/cur/1283599333.1840_11.cthulhu!2,"); diff --git a/mu/mu-cmd-index.cc b/mu/mu-cmd-index.cc index bd3c1c45..fd738098 100644 --- a/mu/mu-cmd-index.cc +++ b/mu/mu-cmd-index.cc @@ -96,7 +96,7 @@ Mu::mu_cmd_index(Mu::Store& store, const MuConfig* opts, GError** err) return MU_ERROR; } - const auto mdir{store.metadata().root_maildir}; + const auto mdir{store.properties().root_maildir}; if (G_UNLIKELY(access(mdir.c_str(), R_OK) != 0)) { mu_util_g_set_error(err, MU_ERROR_FILE, @@ -113,8 +113,8 @@ Mu::mu_cmd_index(Mu::Store& store, const MuConfig* opts, GError** err) std::cout << "lazily "; std::cout << "indexing maildir " << col.fg(Color::Green) - << store.metadata().root_maildir << col.reset() << " -> store " - << col.fg(Color::Green) << store.metadata().database_path << col.reset() + << store.properties().root_maildir << col.reset() << " -> store " + << col.fg(Color::Green) << store.properties().database_path << col.reset() << std::endl; } diff --git a/mu/mu-cmd-server.cc b/mu/mu-cmd-server.cc index cfa326c8..4dc69cdf 100644 --- a/mu/mu-cmd-server.cc +++ b/mu/mu-cmd-server.cc @@ -113,8 +113,8 @@ try { Server server{store, output_sexp_stdout}; g_message("created server with store @ %s; maildir @ %s; debug-mode %s", - store.metadata().database_path.c_str(), - store.metadata().root_maildir.c_str(), + store.properties().database_path.c_str(), + store.properties().root_maildir.c_str(), opts->debug ? "yes" : "no"); tty = ::isatty(::fileno(stdout)); diff --git a/mu/mu-cmd.cc b/mu/mu-cmd.cc index 878185f3..30a076a8 100644 --- a/mu/mu-cmd.cc +++ b/mu/mu-cmd.cc @@ -518,14 +518,14 @@ cmd_info(const Mu::Store& store, const MuConfig* opts, GError** err) { Mu::MaybeAnsi col{!opts->nocolor}; - key_val(col, "maildir", store.metadata().root_maildir); - key_val(col, "database-path", store.metadata().database_path); - key_val(col, "schema-version", store.metadata().schema_version); - key_val(col, "max-message-size", store.metadata().max_message_size); - key_val(col, "batch-size", store.metadata().batch_size); + key_val(col, "maildir", store.properties().root_maildir); + key_val(col, "database-path", store.properties().database_path); + key_val(col, "schema-version", store.properties().schema_version); + key_val(col, "max-message-size", store.properties().max_message_size); + key_val(col, "batch-size", store.properties().batch_size); key_val(col, "messages in store", store.size()); - const auto created{store.metadata().created}; + const auto created{store.properties().created}; const auto tstamp{::localtime(&created)}; #pragma GCC diagnostic push @@ -536,7 +536,7 @@ cmd_info(const Mu::Store& store, const MuConfig* opts, GError** err) key_val(col, "created", tbuf); - const auto addrs{store.metadata().personal_addresses}; + const auto addrs{store.properties().personal_addresses}; if (addrs.empty()) key_val(col, "personal-address", ""); else