From a82bd77d091c5c2b2477f48f16c87f4271cfd4bd Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Sat, 19 Feb 2022 22:08:54 +0200 Subject: [PATCH] lib: rename contacts into contacts-cache Plus dependents. --- lib/Makefile.am | 172 +++++++++---------- lib/meson.build | 4 +- lib/{mu-contacts.cc => mu-contacts-cache.cc} | 32 ++-- lib/{mu-contacts.hh => mu-contacts-cache.hh} | 17 +- lib/mu-server.cc | 3 +- lib/mu-store.cc | 26 +-- lib/mu-store.hh | 8 +- lib/tests/meson.build | 7 +- mu/mu-cmd-cfind.cc | 4 +- mu/mu-cmd.cc | 2 +- 10 files changed, 137 insertions(+), 138 deletions(-) rename lib/{mu-contacts.cc => mu-contacts-cache.cc} (93%) rename lib/{mu-contacts.hh => mu-contacts-cache.hh} (91%) diff --git a/lib/Makefile.am b/lib/Makefile.am index 591604a3..a018c650 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -20,116 +20,116 @@ include $(top_srcdir)/gtest.mk SUBDIRS= utils index -TESTDEFS= \ - -DMU_TESTMAILDIR=\"${abs_srcdir}/testdir\" \ - -DMU_TESTMAILDIR2=\"${abs_srcdir}/testdir2\" \ - -DMU_TESTMAILDIR4=\"${abs_srcdir}/testdir4\" \ - -DABS_CURDIR=\"${abs_builddir}\" \ +TESTDEFS= \ + -DMU_TESTMAILDIR=\"${abs_srcdir}/testdir\" \ + -DMU_TESTMAILDIR2=\"${abs_srcdir}/testdir2\" \ + -DMU_TESTMAILDIR4=\"${abs_srcdir}/testdir4\" \ + -DABS_CURDIR=\"${abs_builddir}\" \ -DABS_SRCDIR=\"${abs_srcdir}\" -AM_CFLAGS= \ - $(WARN_CFLAGS) \ - $(GMIME_CFLAGS) \ - $(XAPIAN_CFLAGS) \ - $(GLIB_CFLAGS) \ - $(GUILE_CFLAGS) \ - $(ASAN_CFLAGS) \ - $(CODE_COVERAGE_CFLAGS) \ - $(TESTDEFS) \ - -Wno-format-nonliteral \ - -Wno-switch-enum \ - -Wno-deprecated-declarations \ +AM_CFLAGS= \ + $(WARN_CFLAGS) \ + $(GMIME_CFLAGS) \ + $(XAPIAN_CFLAGS) \ + $(GLIB_CFLAGS) \ + $(GUILE_CFLAGS) \ + $(ASAN_CFLAGS) \ + $(CODE_COVERAGE_CFLAGS) \ + $(TESTDEFS) \ + -Wno-format-nonliteral \ + -Wno-switch-enum \ + -Wno-deprecated-declarations \ -Wno-inline -AM_CXXFLAGS= \ - $(GMIME_CFLAGS) \ - $(GLIB_CFLAGS) \ - $(GUILE_CFLAGS) \ - $(WARN_CXXFLAGS) \ - $(XAPIAN_CXXFLAGS) \ - $(ASAN_CXXFLAGS) \ - $(CODE_COVERAGE_CFLAGS) \ +AM_CXXFLAGS= \ + $(GMIME_CFLAGS) \ + $(GLIB_CFLAGS) \ + $(GUILE_CFLAGS) \ + $(WARN_CXXFLAGS) \ + $(XAPIAN_CXXFLAGS) \ + $(ASAN_CXXFLAGS) \ + $(CODE_COVERAGE_CFLAGS) \ $(TESTDEFS) -AM_CPPFLAGS= \ +AM_CPPFLAGS= \ $(CODE_COVERAGE_CPPFLAGS) -noinst_LTLIBRARIES= \ +noinst_LTLIBRARIES= \ libmu.la -libmu_la_SOURCES= \ - mu-bookmarks.cc \ - mu-bookmarks.hh \ - mu-contacts.cc \ - mu-contacts.hh \ - mu-data.hh \ - mu-parser.cc \ - mu-parser.hh \ - mu-query.cc \ - mu-query.hh \ - mu-query-results.hh \ - mu-query-match-deciders.cc \ - mu-query-match-deciders.hh \ - mu-query-threads.cc \ - mu-query-threads.hh \ - mu-runtime.cc \ - mu-runtime.hh \ - mu-script.cc \ - mu-script.hh \ - mu-server.cc \ - mu-server.hh \ - mu-store.cc \ - mu-store.hh \ - mu-tokenizer.cc \ - mu-tokenizer.hh \ - mu-tree.hh \ - mu-xapian.cc \ - mu-xapian.hh \ - mu-maildir.cc \ - mu-maildir.hh \ - mu-msg-crypto.cc \ - mu-msg-doc.cc \ - mu-msg-doc.hh \ - mu-msg-fields.c \ - mu-msg-fields.h \ - mu-msg-file.cc \ - mu-msg-file.hh \ - mu-msg-part.cc \ - mu-msg-part.hh \ - mu-msg-priv.hh \ - mu-msg-sexp.cc \ - mu-msg.cc \ - mu-msg.hh \ - mu-message-flags.hh \ - mu-message-flags.cc \ - mu-message-priority.hh \ +libmu_la_SOURCES= \ + mu-bookmarks.cc \ + mu-bookmarks.hh \ + mu-contacts-cache.cc \ + mu-contacts-cache.hh \ + mu-data.hh \ + mu-parser.cc \ + mu-parser.hh \ + mu-query.cc \ + mu-query.hh \ + mu-query-results.hh \ + mu-query-match-deciders.cc \ + mu-query-match-deciders.hh \ + mu-query-threads.cc \ + mu-query-threads.hh \ + mu-runtime.cc \ + mu-runtime.hh \ + mu-script.cc \ + mu-script.hh \ + mu-server.cc \ + mu-server.hh \ + mu-store.cc \ + mu-store.hh \ + mu-tokenizer.cc \ + mu-tokenizer.hh \ + mu-tree.hh \ + mu-xapian.cc \ + mu-xapian.hh \ + mu-maildir.cc \ + mu-maildir.hh \ + mu-msg-crypto.cc \ + mu-msg-doc.cc \ + mu-msg-doc.hh \ + mu-msg-fields.c \ + mu-msg-fields.h \ + mu-msg-file.cc \ + mu-msg-file.hh \ + mu-msg-part.cc \ + mu-msg-part.hh \ + mu-msg-priv.hh \ + mu-msg-sexp.cc \ + mu-msg.cc \ + mu-msg.hh \ + mu-message-flags.hh \ + mu-message-flags.cc \ + mu-message-priority.hh \ mu-message-priority.cc -libmu_la_LIBADD= \ - $(XAPIAN_LIBS) \ - $(GMIME_LIBS) \ - $(GLIB_LIBS) \ - $(GUILE_LIBS) \ - ${builddir}/index/libmu-index.la \ +libmu_la_LIBADD= \ + $(XAPIAN_LIBS) \ + $(GMIME_LIBS) \ + $(GLIB_LIBS) \ + $(GUILE_LIBS) \ + ${builddir}/index/libmu-index.la \ $(CODE_COVERAGE_LIBS) -libmu_la_LDFLAGS= \ +libmu_la_LDFLAGS= \ $(ASAN_LDFLAGS) -noinst_PROGRAMS= \ +noinst_PROGRAMS= \ tokenize -tokenize_SOURCES= \ +tokenize_SOURCES= \ tokenize.cc -tokenize_LDADD= \ - $(WARN_LDFLAGS) \ - libmu.la \ +tokenize_LDADD= \ + $(WARN_LDFLAGS) \ + libmu.la \ utils/libmu-utils.la -EXTRA_DIST= \ +EXTRA_DIST= \ doxyfile.in CLEANFILES=*.log *.trs *core* *vgdump* *.gcda *.gcno diff --git a/lib/meson.build b/lib/meson.build index c9833fb3..d4d085a1 100644 --- a/lib/meson.build +++ b/lib/meson.build @@ -23,8 +23,8 @@ lib_mu=static_library( [ 'mu-bookmarks.cc', 'mu-bookmarks.hh', - 'mu-contacts.cc', - 'mu-contacts.hh', + 'mu-contacts-cache.cc', + 'mu-contacts-cache.hh', 'mu-data.hh', 'mu-parser.cc', 'mu-parser.hh', diff --git a/lib/mu-contacts.cc b/lib/mu-contacts-cache.cc similarity index 93% rename from lib/mu-contacts.cc rename to lib/mu-contacts-cache.cc index dfc9369c..21e9f5c1 100644 --- a/lib/mu-contacts.cc +++ b/lib/mu-contacts-cache.cc @@ -17,7 +17,7 @@ ** */ -#include "mu-contacts.hh" +#include "mu-contacts-cache.hh" #include #include @@ -105,7 +105,7 @@ using ContactUMap = std::unordered_map; using ContactSet = std::set, ContactInfoLessThan>; -struct Contacts::Private { +struct ContactsCache::Private { Private(const std::string& serialized, const StringVec& personal) : contacts_{deserialize(serialized)}, dirty_{0} { @@ -128,7 +128,7 @@ struct Contacts::Private { constexpr auto Separator = "\xff"; // Invalid in UTF-8 void -Contacts::Private::make_personal(const StringVec& personal) +ContactsCache::Private::make_personal(const StringVec& personal) { for (auto&& p : personal) { if (p.empty()) @@ -154,7 +154,7 @@ Contacts::Private::make_personal(const StringVec& personal) } ContactUMap -Contacts::Private::deserialize(const std::string& serialized) const +ContactsCache::Private::deserialize(const std::string& serialized) const { ContactUMap contacts; std::stringstream ss{serialized, std::ios_base::in}; @@ -180,14 +180,14 @@ Contacts::Private::deserialize(const std::string& serialized) const return contacts; } -Contacts::Contacts(const std::string& serialized, const StringVec& personal) +ContactsCache::ContactsCache(const std::string& serialized, const StringVec& personal) : priv_{std::make_unique(serialized, personal)} { } -Contacts::~Contacts() = default; +ContactsCache::~ContactsCache() = default; std::string -Contacts::serialize() const +ContactsCache::serialize() const { std::lock_guard l_{priv_->mtx_}; std::string s; @@ -219,13 +219,13 @@ Contacts::serialize() const } bool -Contacts::dirty() const +ContactsCache::dirty() const { return priv_->dirty_; } const ContactInfo -Contacts::add(ContactInfo&& ci) +ContactsCache::add(ContactInfo&& ci) { std::lock_guard l_{priv_->mtx_}; @@ -261,7 +261,7 @@ Contacts::add(ContactInfo&& ci) } const ContactInfo* -Contacts::_find(const std::string& email) const +ContactsCache::_find(const std::string& email) const { std::lock_guard l_{priv_->mtx_}; @@ -273,7 +273,7 @@ Contacts::_find(const std::string& email) const } void -Contacts::clear() +ContactsCache::clear() { std::lock_guard l_{priv_->mtx_}; @@ -283,7 +283,7 @@ Contacts::clear() } std::size_t -Contacts::size() const +ContactsCache::size() const { std::lock_guard l_{priv_->mtx_}; @@ -291,7 +291,7 @@ Contacts::size() const } void -Contacts::for_each(const EachContactFunc& each_contact) const +ContactsCache::for_each(const EachContactFunc& each_contact) const { std::lock_guard l_{priv_->mtx_}; @@ -308,7 +308,7 @@ Contacts::for_each(const EachContactFunc& each_contact) const } bool -Contacts::is_personal(const std::string& addr) const +ContactsCache::is_personal(const std::string& addr) const { for (auto&& p : priv_->personal_plain_) if (g_ascii_strcasecmp(addr.c_str(), p.c_str()) == 0) @@ -334,7 +334,7 @@ Contacts::is_personal(const std::string& addr) const static void test_mu_contacts_01() { - Mu::Contacts contacts(""); + Mu::ContactsCache contacts(""); g_assert_true(contacts.empty()); g_assert_cmpuint(contacts.size(), ==, 0); @@ -385,7 +385,7 @@ static void test_mu_contacts_02() { Mu::StringVec personal = {"foo@example.com", "bar@cuux.org", "/bar-.*@fnorb.f./"}; - Mu::Contacts contacts{"", personal}; + Mu::ContactsCache contacts{"", personal}; g_assert_true(contacts.is_personal("foo@example.com")); g_assert_true(contacts.is_personal("Bar@CuuX.orG")); diff --git a/lib/mu-contacts.hh b/lib/mu-contacts-cache.hh similarity index 91% rename from lib/mu-contacts.hh rename to lib/mu-contacts-cache.hh index 807abf67..7626667c 100644 --- a/lib/mu-contacts.hh +++ b/lib/mu-contacts-cache.hh @@ -1,5 +1,5 @@ /* -** Copyright (C) 2020 Dirk-Jan C. Binnema +** Copyright (C) 2020-2022 Dirk-Jan C. Binnema ** ** 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 @@ -17,8 +17,8 @@ ** */ -#ifndef __MU_CONTACTS_HH__ -#define __MU_CONTACTS_HH__ +#ifndef __MU_CONTACTS_CACHE_HH__ +#define __MU_CONTACTS_CACHE_HH__ #include #include @@ -62,22 +62,21 @@ struct ContactInfo { int64_t tstamp{}; /**< Time-stamp, as per g_get_monotonic_time */ }; -/// All contacts -class Contacts { +class ContactsCache { public: /** - * Construct a new contacts objects + * Construct a new ContactsCache object * * @param serialized serialized contacts * @param personal personal addresses */ - Contacts(const std::string& serialized = "", const StringVec& personal = {}); + ContactsCache(const std::string& serialized = "", const StringVec& personal = {}); /** * DTOR * */ - ~Contacts(); + ~ContactsCache(); /** * Add a contact @@ -166,4 +165,4 @@ private: } // namespace Mu -#endif /* __MU_CONTACTS_HH__ */ +#endif /* __MU_CONTACTS_CACHE_HH__ */ diff --git a/lib/mu-server.cc b/lib/mu-server.cc index 68bc5a04..0d1dc78b 100644 --- a/lib/mu-server.cc +++ b/lib/mu-server.cc @@ -42,7 +42,6 @@ #include "index/mu-indexer.hh" #include "mu-store.hh" #include "mu-msg-part.hh" -#include "mu-contacts.hh" #include "utils/mu-str.h" #include "utils/mu-utils.hh" @@ -523,7 +522,7 @@ Server::Private::contacts_handler(const Parameters& params) auto rank{0}; Sexp::List contacts; - store().contacts().for_each([&](const ContactInfo& ci) { + store().contacts_cache().for_each([&](const ContactInfo& ci) { rank++; /* since the last time we got some contacts */ diff --git a/lib/mu-store.cc b/lib/mu-store.cc index 9312cafb..e7327fe9 100644 --- a/lib/mu-store.cc +++ b/lib/mu-store.cc @@ -118,7 +118,7 @@ struct Store::Private { : read_only_{readonly}, db_{make_xapian_db(path, read_only_ ? XapianOpts::ReadOnly : XapianOpts::Open)}, - properties_{make_properties(path)}, contacts_{db().get_metadata(ContactsKey), + properties_{make_properties(path)}, contacts_cache_{db().get_metadata(ContactsKey), properties_.personal_addresses} { } @@ -129,7 +129,7 @@ struct Store::Private { const Store::Config& conf) : read_only_{false}, db_{make_xapian_db(path, XapianOpts::CreateOverwrite)}, properties_{init_metadata(conf, path, root_maildir, personal_addresses)}, - contacts_{"", properties_.personal_addresses} + contacts_cache_{"", properties_.personal_addresses} { } @@ -138,7 +138,7 @@ struct Store::Private { const Store::Config& conf) : read_only_{false}, db_{make_xapian_db("", XapianOpts::InMemory)}, properties_{init_metadata(conf, "", root_maildir, personal_addresses)}, - contacts_{"", properties_.personal_addresses} + contacts_cache_{"", properties_.personal_addresses} { } @@ -210,10 +210,10 @@ struct Store::Private { return; // not supported or not in transaction if (force || transaction_size_ >= properties_.batch_size) { - if (contacts_.dirty()) { + if (contacts_cache_.dirty()) { xapian_try([&] { writable_db().set_metadata(ContactsKey, - contacts_.serialize()); + contacts_cache_.serialize()); }); } g_debug("committing transaction (n=%zu,%zu)", @@ -310,7 +310,7 @@ struct Store::Private { std::unique_ptr db_; const Store::Properties properties_; - Contacts contacts_; + ContactsCache contacts_cache_; std::unique_ptr indexer_; size_t transaction_size_{}; @@ -365,10 +365,10 @@ Store::properties() const return priv_->properties_; } -const Contacts& -Store::contacts() const +const ContactsCache& +Store::contacts_cache() const { - return priv_->contacts_; + return priv_->contacts_cache_; } const Xapian::Database& @@ -980,7 +980,7 @@ xapian_pfx(const MessageContact& contact) static void add_contacts_terms_values(Xapian::Document& doc, MuMsg *msg, - Contacts& contacts_store) + ContactsCache& contacts_cache) { Xapian::TermGenerator termgen; termgen.set_document(doc); @@ -1007,11 +1007,11 @@ add_contacts_terms_values(Xapian::Document& doc, MuMsg *msg, termgen.index_text_without_positions(contact.email, 1, pfx); /* and add to the contact store.*/ - contacts_store.add(ContactInfo{ + contacts_cache.add(ContactInfo{ contact.display_name(), contact.email, contact.name, - contacts_store.is_personal(contact.email), + contacts_cache.is_personal(contact.email), contact.message_date}); } } @@ -1022,7 +1022,7 @@ Store::Private::new_doc_from_message(MuMsg* msg) Xapian::Document doc; MsgDoc docinfo = {&doc, msg, this, 0, NULL}; - add_contacts_terms_values(doc, msg, contacts_); + add_contacts_terms_values(doc, msg, contacts_cache_); mu_msg_field_foreach((MuMsgFieldForeachFunc)add_terms_values, &docinfo); // g_printerr ("\n--%s\n--\n", doc.serialise().c_str()); diff --git a/lib/mu-store.hh b/lib/mu-store.hh index 2f32b7e9..bfa3ef00 100644 --- a/lib/mu-store.hh +++ b/lib/mu-store.hh @@ -1,5 +1,5 @@ /* -** Copyright (C) 2021 Dirk-Jan C. Binnema +** Copyright (C) 2022 Dirk-Jan C. Binnema ** ** 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 @@ -27,7 +27,7 @@ #include #include -#include "mu-contacts.hh" +#include "mu-contacts-cache.hh" #include #include @@ -111,11 +111,11 @@ public: */ const Properties& properties() const; /** - * Get the Contacts object for this store + * Get the ContactsCache object for this store * * @return the Contacts object */ - const Contacts& contacts() const; + const ContactsCache& contacts_cache() const; /** * Get the underlying Xapian database for this store. diff --git a/lib/tests/meson.build b/lib/tests/meson.build index 2436a38f..ca428f6c 100644 --- a/lib/tests/meson.build +++ b/lib/tests/meson.build @@ -55,9 +55,9 @@ test('test_threads', install: false, cpp_args: ['-DBUILD_TESTS'], dependencies: [glib_dep, lib_mu_dep, lib_test_mu_common_dep])) -test('test_contacts', +test('test_contacts-cache', executable('test-contacts', - '../mu-contacts.cc', + '../mu-contacts-cache.cc', install: false, cpp_args: ['-DBUILD_TESTS'], dependencies: [glib_dep, lib_mu_dep, lib_test_mu_common_dep])) @@ -67,7 +67,8 @@ test('test_message_contact', '../mu-message-contact.cc', install: false, cpp_args: ['-DBUILD_TESTS'], - dependencies: [glib_dep, gmime_dep, lib_mu_dep, lib_test_mu_common_dep])) + dependencies: [glib_dep, gmime_dep, lib_mu_dep, + lib_test_mu_common_dep])) test('test_parser', executable('test-parser', diff --git a/mu/mu-cmd-cfind.cc b/mu/mu-cmd-cfind.cc index 362fca5b..221b99c9 100644 --- a/mu/mu-cmd-cfind.cc +++ b/mu/mu-cmd-cfind.cc @@ -26,7 +26,7 @@ #include #include "mu-cmd.hh" -#include "mu-contacts.hh" +#include "mu-contacts-cache.hh" #include "mu-runtime.hh" #include "utils/mu-util.h" @@ -363,7 +363,7 @@ run_cmd_cfind(const Mu::Store& store, print_header(format); - store.contacts().for_each([&](const auto& ci) { each_contact(ci, ecdata); }); + store.contacts_cache().for_each([&](const auto& ci) { each_contact(ci, ecdata); }); g_hash_table_unref(ecdata.nicks); diff --git a/mu/mu-cmd.cc b/mu/mu-cmd.cc index 6544e221..5aa492cf 100644 --- a/mu/mu-cmd.cc +++ b/mu/mu-cmd.cc @@ -32,7 +32,7 @@ #include "mu-msg-part.hh" #include "mu-cmd.hh" #include "mu-maildir.hh" -#include "mu-contacts.hh" +#include "mu-contacts-cache.hh" #include "mu-runtime.hh" #include "mu-message-flags.hh"