mirror of https://github.com/djcb/mu.git
* 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:
parent
95bb6f9756
commit
044db7ea80
|
@ -83,15 +83,30 @@ _insert_or_update_maybe (const char* fullpath, time_t filestamp,
|
||||||
MuIndexCallbackData *data, gboolean *updated)
|
MuIndexCallbackData *data, gboolean *updated)
|
||||||
{
|
{
|
||||||
MuMsgGMime *msg;
|
MuMsgGMime *msg;
|
||||||
|
|
||||||
*updated = FALSE;
|
*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);
|
msg = mu_msg_gmime_new (fullpath);
|
||||||
if (!msg) {
|
if (!msg) {
|
||||||
g_warning ("%s: failed to create mu_msg for %s",
|
g_warning ("%s: failed to create mu_msg for %s",
|
||||||
|
|
|
@ -300,8 +300,10 @@ mu_store_xapian_remove (MuStoreXapian *store, const char* msgpath)
|
||||||
g_debug ("deleting %s", msgpath);
|
g_debug ("deleting %s", msgpath);
|
||||||
|
|
||||||
++store->_processed;
|
++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;
|
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
|
time_t
|
||||||
mu_store_xapian_get_timestamp (MuStoreXapian *store, const char* msgpath)
|
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);
|
g_return_val_if_fail (func, MU_ERROR);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Xapian::Enquire enq (*self->_db);
|
Xapian::Enquire enq (*self->_db);
|
||||||
|
|
||||||
|
|
||||||
enq.set_query (Xapian::Query::MatchAll);
|
enq.set_query (Xapian::Query::MatchAll);
|
||||||
enq.set_cutoff (0,0);
|
enq.set_cutoff (0,0);
|
||||||
|
|
|
@ -82,6 +82,18 @@ MuResult mu_store_xapian_store (MuStoreXapian *store,
|
||||||
MuResult mu_store_xapian_remove (MuStoreXapian *store,
|
MuResult mu_store_xapian_remove (MuStoreXapian *store,
|
||||||
const char* msgpath);
|
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
|
* store a timestamp for a directory
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue