From 044db7ea807128873b7144a589539bc522aeff0b Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Mon, 11 Jan 2010 20:46:14 +0200 Subject: [PATCH] * mu-store/index: better up-to-date check: see if message is in db already mu-store-xapian: add mu_store_contains_message; mu_index: update the check we cannot just rely on the timestamp, because messages may be moved from elsewhere, e.g. from 'new' to 'cur' --- src/mu-index.c | 27 +++++++++++++++++++++------ src/mu-store-xapian.cc | 24 +++++++++++++++++++++--- src/mu-store-xapian.h | 12 ++++++++++++ 3 files changed, 54 insertions(+), 9 deletions(-) diff --git a/src/mu-index.c b/src/mu-index.c index 010459e8..716815f9 100644 --- a/src/mu-index.c +++ b/src/mu-index.c @@ -83,15 +83,30 @@ _insert_or_update_maybe (const char* fullpath, time_t filestamp, MuIndexCallbackData *data, gboolean *updated) { MuMsgGMime *msg; - + *updated = FALSE; - g_debug ("msg: %s (%u)", fullpath,(size_t)filestamp); + /* checks to determine if we need to (re)index this message */ + do { + /* unconditionally reindex */ + if (data->_reindex) + break; + + /* it's not in the database yet */ + if (!mu_store_contains_message (data->_xapian, fullpath)) { + g_debug ("not yet in db: %s", fullpath); + break; + } + + /* it's there, but it's not up to date */ + if ((size_t)filestamp >= (size_t)data->_dirstamp) + break; + + return MU_OK; /* nope: no need to insert/update! */ + + } while (0); + - if (!data->_reindex) - if ((size_t)filestamp <= (size_t)data->_dirstamp) - return MU_OK; - msg = mu_msg_gmime_new (fullpath); if (!msg) { g_warning ("%s: failed to create mu_msg for %s", diff --git a/src/mu-store-xapian.cc b/src/mu-store-xapian.cc index ce0bc633..201dc9d4 100644 --- a/src/mu-store-xapian.cc +++ b/src/mu-store-xapian.cc @@ -300,8 +300,10 @@ mu_store_xapian_remove (MuStoreXapian *store, const char* msgpath) g_debug ("deleting %s", msgpath); ++store->_processed; - _commit_transaction_if (store, - store->_processed % store->_trx_size == 0); + + /* do we need to commit now? */ + bool commit_now = store->_processed % store->_trx_size == 0; + _commit_transaction_if (store, commit_now); return MU_OK; @@ -309,6 +311,21 @@ mu_store_xapian_remove (MuStoreXapian *store, const char* msgpath) } +gboolean +mu_store_contains_message (MuStoreXapian *store, const char* path) +{ + g_return_val_if_fail (store, NULL); + g_return_val_if_fail (path, NULL); + + try { + const std::string uid (_get_message_uid(path)); + return store->_db->term_exists (uid) ? TRUE: FALSE; + + } MU_XAPIAN_CATCH_BLOCK_RETURN (FALSE); +} + + + time_t mu_store_xapian_get_timestamp (MuStoreXapian *store, const char* msgpath) { @@ -352,7 +369,8 @@ mu_store_xapian_foreach (MuStoreXapian *self, g_return_val_if_fail (func, MU_ERROR); try { - Xapian::Enquire enq (*self->_db); + Xapian::Enquire enq (*self->_db); + enq.set_query (Xapian::Query::MatchAll); enq.set_cutoff (0,0); diff --git a/src/mu-store-xapian.h b/src/mu-store-xapian.h index 5e0fbcb8..3e82dd44 100644 --- a/src/mu-store-xapian.h +++ b/src/mu-store-xapian.h @@ -82,6 +82,18 @@ MuResult mu_store_xapian_store (MuStoreXapian *store, MuResult mu_store_xapian_remove (MuStoreXapian *store, const char* msgpath); + +/** + * does a certain message exist in the database already? + * + * @param store a store + * @param path the message path + * + * @return + */ +gboolean mu_store_contains_message (MuStoreXapian *store, + const char* path); + /** * store a timestamp for a directory *