* 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'
This commit is contained in:
Dirk-Jan C. Binnema 2010-01-11 20:46:14 +02:00
parent 95bb6f9756
commit 044db7ea80
3 changed files with 54 additions and 9 deletions

View File

@ -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",

View File

@ -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);

View File

@ -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
*