mirror of https://github.com/djcb/mu.git
* mu_store_xapian.{cc,h}: use new macros, cleanups. add mu_store_xapian_flush
This commit is contained in:
parent
0bb240cbb0
commit
b6ba6176a4
|
@ -43,26 +43,26 @@ struct _MuStoreXapian {
|
||||||
};
|
};
|
||||||
|
|
||||||
MuStoreXapian*
|
MuStoreXapian*
|
||||||
mu_store_xapian_new (const char* path)
|
mu_store_xapian_new (const char* xpath)
|
||||||
{
|
{
|
||||||
MuStoreXapian *store;
|
MuStoreXapian *store;
|
||||||
|
|
||||||
g_return_val_if_fail (path, NULL);
|
g_return_val_if_fail (xpath, NULL);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
store = g_new0(MuStoreXapian,1);
|
store = g_new0(MuStoreXapian,1);
|
||||||
store->_db = new Xapian::WritableDatabase
|
store->_db = new Xapian::WritableDatabase
|
||||||
(path,Xapian::DB_CREATE_OR_OPEN);
|
(xpath, Xapian::DB_CREATE_OR_OPEN);
|
||||||
|
|
||||||
/* keep count of processed docs */
|
/* keep count of processed docs */
|
||||||
store->_trx_size = MU_STORE_XAPIAN_TRX_SIZE;
|
store->_trx_size = MU_STORE_XAPIAN_TRX_SIZE;
|
||||||
store->_in_transaction = false;
|
store->_in_transaction = false;
|
||||||
store->_processed = 0;
|
store->_processed = 0;
|
||||||
|
|
||||||
g_message ("%s: opened %s", __FUNCTION__, path);
|
MU_WRITE_LOG ("%s: opened %s", __FUNCTION__, xpath);
|
||||||
return store;
|
return store;
|
||||||
|
|
||||||
} MU_UTIL_XAPIAN_CATCH_BLOCK;
|
} MU_XAPIAN_CATCH_BLOCK;
|
||||||
|
|
||||||
delete store->_db;
|
delete store->_db;
|
||||||
g_free (store);
|
g_free (store);
|
||||||
|
@ -75,7 +75,7 @@ static void
|
||||||
_begin_transaction_if (MuStoreXapian *store, gboolean cond)
|
_begin_transaction_if (MuStoreXapian *store, gboolean cond)
|
||||||
{
|
{
|
||||||
if (cond) {
|
if (cond) {
|
||||||
g_message ("beginning Xapian transaction");
|
g_debug ("beginning Xapian transaction");
|
||||||
store->_db->begin_transaction();
|
store->_db->begin_transaction();
|
||||||
store->_in_transaction = true;
|
store->_in_transaction = true;
|
||||||
}
|
}
|
||||||
|
@ -85,7 +85,7 @@ static void
|
||||||
_commit_transaction_if (MuStoreXapian *store, gboolean cond)
|
_commit_transaction_if (MuStoreXapian *store, gboolean cond)
|
||||||
{
|
{
|
||||||
if (cond) {
|
if (cond) {
|
||||||
g_message ("starting Xapian transaction");
|
g_debug ("comitting Xapian transaction");
|
||||||
store->_in_transaction = false;
|
store->_in_transaction = false;
|
||||||
store->_db->commit_transaction();
|
store->_db->commit_transaction();
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ static void
|
||||||
_rollback_transaction_if (MuStoreXapian *store, gboolean cond)
|
_rollback_transaction_if (MuStoreXapian *store, gboolean cond)
|
||||||
{
|
{
|
||||||
if (cond) {
|
if (cond) {
|
||||||
g_message ("rolling back Xapian transaction");
|
g_debug ("rolling back Xapian transaction");
|
||||||
store->_in_transaction = false;
|
store->_in_transaction = false;
|
||||||
store->_db->cancel_transaction();
|
store->_db->cancel_transaction();
|
||||||
}
|
}
|
||||||
|
@ -109,16 +109,28 @@ mu_store_xapian_destroy (MuStoreXapian *store)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
_commit_transaction_if (store, store->_in_transaction);
|
mu_store_xapian_flush (store);
|
||||||
store->_db->flush();
|
|
||||||
|
MU_WRITE_LOG ("closing xapian database with %d documents",
|
||||||
g_message ("closing xapian database with %d documents",
|
(int)store->_db->get_doccount());
|
||||||
(int)store->_db->get_doccount());
|
|
||||||
|
|
||||||
delete store->_db;
|
delete store->_db;
|
||||||
g_free (store);
|
g_free (store);
|
||||||
|
|
||||||
} MU_UTIL_XAPIAN_CATCH_BLOCK;
|
} MU_XAPIAN_CATCH_BLOCK;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
mu_store_xapian_flush (MuStoreXapian *store)
|
||||||
|
{
|
||||||
|
g_return_if_fail (store);
|
||||||
|
|
||||||
|
try {
|
||||||
|
_commit_transaction_if (store, store->_in_transaction);
|
||||||
|
store->_db->flush ();
|
||||||
|
|
||||||
|
} MU_XAPIAN_CATCH_BLOCK;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -245,7 +257,6 @@ mu_store_xapian_store (MuStoreXapian *store, MuMsgGMime *msg)
|
||||||
try {
|
try {
|
||||||
Xapian::Document newdoc;
|
Xapian::Document newdoc;
|
||||||
Xapian::docid id;
|
Xapian::docid id;
|
||||||
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));
|
||||||
|
|
||||||
|
@ -259,11 +270,12 @@ 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);
|
||||||
++store->_processed;
|
++store->_processed;
|
||||||
_commit_transaction_if (store, store->_processed % store->_trx_size == 0);
|
_commit_transaction_if (store,
|
||||||
|
store->_processed % store->_trx_size == 0);
|
||||||
|
|
||||||
return MU_OK;
|
return MU_OK;
|
||||||
|
|
||||||
} MU_UTIL_XAPIAN_CATCH_BLOCK;
|
} MU_XAPIAN_CATCH_BLOCK;
|
||||||
|
|
||||||
_rollback_transaction_if (store, store->_in_transaction);
|
_rollback_transaction_if (store, store->_in_transaction);
|
||||||
|
|
||||||
|
@ -283,14 +295,15 @@ mu_store_xapian_remove (MuStoreXapian *store, const char* msgpath)
|
||||||
_begin_transaction_if (store, !store->_in_transaction);
|
_begin_transaction_if (store, !store->_in_transaction);
|
||||||
|
|
||||||
store->_db->delete_document (uid);
|
store->_db->delete_document (uid);
|
||||||
g_message ("deleting %s", msgpath);
|
g_debug ("deleting %s", msgpath);
|
||||||
|
|
||||||
++store->_processed;
|
++store->_processed;
|
||||||
_commit_transaction_if (store, store->_processed % store->_trx_size == 0);
|
_commit_transaction_if (store,
|
||||||
|
store->_processed % store->_trx_size == 0);
|
||||||
|
|
||||||
return MU_OK;
|
return MU_OK;
|
||||||
|
|
||||||
} MU_UTIL_XAPIAN_CATCH_BLOCK_RETURN (MU_ERROR);
|
} MU_XAPIAN_CATCH_BLOCK_RETURN (MU_ERROR);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -307,7 +320,7 @@ mu_store_xapian_get_timestamp (MuStoreXapian *store, const char* msgpath)
|
||||||
|
|
||||||
return (time_t) g_ascii_strtoull (stamp.c_str(), NULL, 10);
|
return (time_t) g_ascii_strtoull (stamp.c_str(), NULL, 10);
|
||||||
|
|
||||||
} MU_UTIL_XAPIAN_CATCH_BLOCK_RETURN (0);
|
} MU_XAPIAN_CATCH_BLOCK_RETURN (0);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -325,7 +338,7 @@ mu_store_xapian_set_timestamp (MuStoreXapian *store, const char* msgpath,
|
||||||
sprintf (buf, "%" G_GUINT64_FORMAT, (guint64)stamp);
|
sprintf (buf, "%" G_GUINT64_FORMAT, (guint64)stamp);
|
||||||
store->_db->set_metadata (msgpath, buf);
|
store->_db->set_metadata (msgpath, buf);
|
||||||
|
|
||||||
} MU_UTIL_XAPIAN_CATCH_BLOCK;
|
} MU_XAPIAN_CATCH_BLOCK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -358,7 +371,7 @@ mu_store_xapian_foreach (MuStoreXapian *self,
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
} MU_UTIL_XAPIAN_CATCH_BLOCK_RETURN (MU_ERROR);
|
} MU_XAPIAN_CATCH_BLOCK_RETURN (MU_ERROR);
|
||||||
|
|
||||||
return MU_OK;
|
return MU_OK;
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,6 +49,13 @@ MuStoreXapian* mu_store_xapian_new (const char* path);
|
||||||
void mu_store_xapian_destroy (MuStoreXapian *store);
|
void mu_store_xapian_destroy (MuStoreXapian *store);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* try to flush/commit all outstanding work
|
||||||
|
*
|
||||||
|
* @param store a valid xapian store
|
||||||
|
*/
|
||||||
|
void mu_store_xapian_flush (MuStoreXapian *store);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* store an email message in the XapianStore
|
* store an email message in the XapianStore
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue