* mu-index, mu-store-xapian.cc: activate _remove
This commit is contained in:
@ -303,10 +303,15 @@ typedef struct _CleanupData CleanupData;
|
|||||||
static MuResult
|
static MuResult
|
||||||
_foreach_doc_cb (const char* path, CleanupData *cudata)
|
_foreach_doc_cb (const char* path, CleanupData *cudata)
|
||||||
{
|
{
|
||||||
|
MuResult rv;
|
||||||
|
|
||||||
if (access (path, R_OK) != 0) {
|
if (access (path, R_OK) != 0) {
|
||||||
g_message ("not readable: %s; removing",
|
|
||||||
path);
|
g_message ("not readable: %s; removing", path);
|
||||||
/* FIXME: delete from db */
|
rv = mu_store_xapian_remove (cudata->_xapian, path);
|
||||||
|
if (rv != MU_OK)
|
||||||
|
return rv; /* something went wrong... bail out */
|
||||||
|
|
||||||
if (cudata->_stats)
|
if (cudata->_stats)
|
||||||
++cudata->_stats->_cleaned_up;
|
++cudata->_stats->_cleaned_up;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -158,8 +158,6 @@ mu_query_xapian_destroy (MuQueryXapian *self)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
MuMsgXapian*
|
MuMsgXapian*
|
||||||
mu_query_xapian_run (MuQueryXapian *self, const char* searchexpr,
|
mu_query_xapian_run (MuQueryXapian *self, const char* searchexpr,
|
||||||
const MuMsgField* sortfield, gboolean ascending)
|
const MuMsgField* sortfield, gboolean ascending)
|
||||||
|
|||||||
@ -31,7 +31,7 @@
|
|||||||
#include "mu-util.h"
|
#include "mu-util.h"
|
||||||
|
|
||||||
/* number of new messages after which we commit to the database */
|
/* number of new messages after which we commit to the database */
|
||||||
#define MU_STORE_XAPIAN_TRANSACTION_SIZE 2000
|
#define MU_STORE_XAPIAN_TRX_SIZE 2000
|
||||||
|
|
||||||
struct _MuStoreXapian {
|
struct _MuStoreXapian {
|
||||||
Xapian::WritableDatabase *_db;
|
Xapian::WritableDatabase *_db;
|
||||||
@ -39,7 +39,7 @@ struct _MuStoreXapian {
|
|||||||
/* transaction handling */
|
/* transaction handling */
|
||||||
bool _in_transaction;
|
bool _in_transaction;
|
||||||
int _processed;
|
int _processed;
|
||||||
size_t _transaction_size;
|
size_t _trx_size;
|
||||||
};
|
};
|
||||||
|
|
||||||
MuStoreXapian*
|
MuStoreXapian*
|
||||||
@ -55,7 +55,7 @@ mu_store_xapian_new (const char* path)
|
|||||||
(path,Xapian::DB_CREATE_OR_OPEN);
|
(path,Xapian::DB_CREATE_OR_OPEN);
|
||||||
|
|
||||||
/* keep count of processed docs */
|
/* keep count of processed docs */
|
||||||
store->_transaction_size = MU_STORE_XAPIAN_TRANSACTION_SIZE;
|
store->_trx_size = MU_STORE_XAPIAN_TRX_SIZE;
|
||||||
store->_in_transaction = false;
|
store->_in_transaction = false;
|
||||||
store->_processed = 0;
|
store->_processed = 0;
|
||||||
|
|
||||||
@ -71,17 +71,45 @@ mu_store_xapian_new (const char* path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
_begin_transaction_if (MuStoreXapian *store, gboolean cond)
|
||||||
|
{
|
||||||
|
if (cond) {
|
||||||
|
g_message ("beginning Xapian transaction");
|
||||||
|
store->_db->begin_transaction();
|
||||||
|
store->_in_transaction = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_commit_transaction_if (MuStoreXapian *store, gboolean cond)
|
||||||
|
{
|
||||||
|
if (cond) {
|
||||||
|
g_message ("starting Xapian transaction");
|
||||||
|
store->_in_transaction = false;
|
||||||
|
store->_db->commit_transaction();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_rollback_transaction_if (MuStoreXapian *store, gboolean cond)
|
||||||
|
{
|
||||||
|
if (cond) {
|
||||||
|
g_message ("rolling back Xapian transaction");
|
||||||
|
store->_in_transaction = false;
|
||||||
|
store->_db->cancel_transaction();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
mu_store_xapian_destroy (MuStoreXapian *store)
|
mu_store_xapian_destroy (MuStoreXapian *store)
|
||||||
{
|
{
|
||||||
if (!store)
|
if (!store)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (store->_in_transaction) {
|
_commit_transaction_if (store, store->_in_transaction);
|
||||||
store->_in_transaction = false;
|
|
||||||
store->_db->commit_transaction();
|
|
||||||
}
|
|
||||||
store->_db->flush();
|
store->_db->flush();
|
||||||
|
|
||||||
g_message ("closing xapian database with %d documents",
|
g_message ("closing xapian database with %d documents",
|
||||||
@ -190,16 +218,21 @@ add_terms_values (const MuMsgField* field, MsgDoc* msgdoc)
|
|||||||
|
|
||||||
/* get a unique id for this message */
|
/* get a unique id for this message */
|
||||||
static std::string
|
static std::string
|
||||||
_get_message_uid (MuMsgGMime *msg)
|
_get_message_uid (const char* path)
|
||||||
{
|
{
|
||||||
static const MuMsgField* pathfield =
|
static const MuMsgField* pathfield =
|
||||||
mu_msg_field_from_id(MU_MSG_FIELD_ID_PATH);
|
mu_msg_field_from_id(MU_MSG_FIELD_ID_PATH);
|
||||||
static const std::string pathprefix
|
static const std::string pathprefix
|
||||||
(mu_msg_field_xapian_prefix(pathfield));
|
(mu_msg_field_xapian_prefix(pathfield));
|
||||||
|
|
||||||
return pathprefix + mu_msg_gmime_get_path(msg);
|
return pathprefix + path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static std::string
|
||||||
|
_get_message_uid (MuMsgGMime *msg)
|
||||||
|
{
|
||||||
|
return _get_message_uid (mu_msg_gmime_get_path(msg));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -215,12 +248,8 @@ mu_store_xapian_store (MuStoreXapian *store, MuMsgGMime *msg)
|
|||||||
gboolean commit_now;
|
gboolean commit_now;
|
||||||
MsgDoc msgdoc = { &newdoc, msg };
|
MsgDoc msgdoc = { &newdoc, msg };
|
||||||
const std::string uid(_get_message_uid(msg));
|
const std::string uid(_get_message_uid(msg));
|
||||||
|
|
||||||
// start transaction if needed
|
_begin_transaction_if (store, !store->_in_transaction);
|
||||||
if (!store->_in_transaction) {
|
|
||||||
store->_db->begin_transaction();
|
|
||||||
store->_in_transaction = true;
|
|
||||||
}
|
|
||||||
/* we must add a unique term, so we can replace matching
|
/* we must add a unique term, so we can replace matching
|
||||||
* documents */
|
* documents */
|
||||||
newdoc.add_term (uid);
|
newdoc.add_term (uid);
|
||||||
@ -229,20 +258,14 @@ mu_store_xapian_store (MuStoreXapian *store, MuMsgGMime *msg)
|
|||||||
|
|
||||||
/* we replace all existing documents for this file */
|
/* we replace all existing documents for this file */
|
||||||
id = store->_db->replace_document (uid, newdoc);
|
id = store->_db->replace_document (uid, newdoc);
|
||||||
commit_now = ++store->_processed % store->_transaction_size == 0;
|
++store->_processed;
|
||||||
if (commit_now) {
|
_commit_transaction_if (store, store->_processed % store->_trx_size == 0);
|
||||||
store->_in_transaction = false;
|
|
||||||
store->_db->commit_transaction();
|
|
||||||
}
|
|
||||||
|
|
||||||
return MU_OK;
|
return MU_OK;
|
||||||
|
|
||||||
} MU_UTIL_XAPIAN_CATCH_BLOCK;
|
} MU_UTIL_XAPIAN_CATCH_BLOCK;
|
||||||
|
|
||||||
if (store->_in_transaction) {
|
_rollback_transaction_if (store, store->_in_transaction);
|
||||||
store->_in_transaction = false;
|
|
||||||
store->_db->cancel_transaction();
|
|
||||||
}
|
|
||||||
|
|
||||||
return MU_ERROR;
|
return MU_ERROR;
|
||||||
}
|
}
|
||||||
@ -255,7 +278,17 @@ mu_store_xapian_remove (MuStoreXapian *store, const char* msgpath)
|
|||||||
g_return_val_if_fail (msgpath, MU_ERROR);
|
g_return_val_if_fail (msgpath, MU_ERROR);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return MU_OK; /* FIXME: TODO: */
|
const std::string uid (_get_message_uid (msgpath));
|
||||||
|
|
||||||
|
_begin_transaction_if (store, !store->_in_transaction);
|
||||||
|
|
||||||
|
store->_db->delete_document (uid);
|
||||||
|
g_message ("deleting %s", msgpath);
|
||||||
|
|
||||||
|
++store->_processed;
|
||||||
|
_commit_transaction_if (store, store->_processed % store->_trx_size == 0);
|
||||||
|
|
||||||
|
return MU_OK;
|
||||||
|
|
||||||
} MU_UTIL_XAPIAN_CATCH_BLOCK_RETURN (MU_ERROR);
|
} MU_UTIL_XAPIAN_CATCH_BLOCK_RETURN (MU_ERROR);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user