* <many>: add option to change the batch size for xapian transactions
This commit is contained in:
@ -27,10 +27,28 @@
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
enum _MuConfigCmd {
|
||||
MU_CONFIG_CMD_INDEX,
|
||||
MU_CONFIG_CMD_FIND,
|
||||
MU_CONFIG_CMD_CLEANUP,
|
||||
MU_CONFIG_CMD_MKDIR,
|
||||
MU_CONFIG_CMD_VIEW,
|
||||
MU_CONFIG_CMD_EXTRACT,
|
||||
MU_CONFIG_CMD_NONE,
|
||||
|
||||
MU_CONFIG_CMD_UNKNOWN
|
||||
};
|
||||
typedef enum _MuConfigCmd MuConfigCmd;
|
||||
|
||||
|
||||
|
||||
/* struct with all configuration options for mu; it will be filled
|
||||
* from the config file, and/or command line arguments */
|
||||
|
||||
struct _MuConfigOptions {
|
||||
|
||||
MuConfigCmd cmd; /* the command, or MU_CONFIG_CMD_NONE */
|
||||
const char *cmdstr; /* cmd string, for user info */
|
||||
|
||||
/* general options */
|
||||
gboolean quiet; /* don't give any output */
|
||||
@ -47,6 +65,9 @@ struct _MuConfigOptions {
|
||||
gboolean rebuild; /* empty the database before indexing */
|
||||
gboolean autoupgrade; /* automatically upgrade db
|
||||
* when needed */
|
||||
int xbatchsize; /* batchsize for xapian commits, or 0 for default
|
||||
* */
|
||||
|
||||
/* options for querying */
|
||||
gboolean xquery; /* give the Xapian query instead of
|
||||
search results */
|
||||
|
||||
@ -41,14 +41,14 @@ struct _MuIndex {
|
||||
};
|
||||
|
||||
MuIndex*
|
||||
mu_index_new (const char *xpath, GError **err)
|
||||
mu_index_new (const char *xpath, guint xbatchsize, GError **err)
|
||||
{
|
||||
MuIndex *index;
|
||||
|
||||
g_return_val_if_fail (xpath, NULL);
|
||||
|
||||
index = g_new0 (MuIndex, 1);
|
||||
index->_xapian = mu_store_new (xpath, err);
|
||||
index->_xapian = mu_store_new (xpath, xbatchsize, err);
|
||||
|
||||
if (!index->_xapian) {
|
||||
g_warning ("%s: failed to open xapian store (%s)",
|
||||
|
||||
@ -51,7 +51,7 @@ typedef struct _MuIndexStats MuIndexStats;
|
||||
*
|
||||
* @return a new MuIndex instance, or NULL in case of error
|
||||
*/
|
||||
MuIndex* mu_index_new (const char* muhome, GError **err)
|
||||
MuIndex* mu_index_new (const char* muhome, guint batchsize, GError **err)
|
||||
G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
|
||||
|
||||
|
||||
|
||||
@ -32,8 +32,8 @@
|
||||
#include "mu-str.h"
|
||||
#include "mu-msg-flags.h"
|
||||
|
||||
/* number of new messages after which we commit to the database */
|
||||
#define MU_STORE_TRX_SIZE 6666
|
||||
/* by default, use transactions of 30000 messages */
|
||||
#define MU_STORE_DEFAULT_TRX_SIZE 30000
|
||||
|
||||
/* http://article.gmane.org/gmane.comp.search.xapian.general/3656 */
|
||||
#define MU_STORE_MAX_TERM_LENGTH 240
|
||||
@ -47,6 +47,7 @@ struct _MuStore {
|
||||
bool _in_transaction;
|
||||
int _processed;
|
||||
size_t _trx_size;
|
||||
guint _batchsize; /* batch size of a xapian transaction */
|
||||
};
|
||||
|
||||
|
||||
@ -115,7 +116,7 @@ check_version (MuStore *store)
|
||||
}
|
||||
|
||||
MuStore*
|
||||
mu_store_new (const char* xpath, GError **err)
|
||||
mu_store_new (const char* xpath, guint batchsize, GError **err)
|
||||
{
|
||||
MuStore *store (0);
|
||||
|
||||
@ -131,14 +132,15 @@ mu_store_new (const char* xpath, GError **err)
|
||||
}
|
||||
|
||||
/* keep count of processed docs */
|
||||
store->_trx_size = MU_STORE_TRX_SIZE;
|
||||
store->_in_transaction = false;
|
||||
store->_processed = 0;
|
||||
store->_processed = 0;
|
||||
store->_trx_size = batchsize ? batchsize : MU_STORE_DEFAULT_TRX_SIZE;
|
||||
|
||||
add_synonyms (store);
|
||||
|
||||
MU_WRITE_LOG ("%s: opened %s", __FUNCTION__, xpath);
|
||||
|
||||
MU_WRITE_LOG ("%s: opened %s (batch size: %u)",
|
||||
__FUNCTION__, xpath, store->_trx_size);
|
||||
|
||||
return store;
|
||||
|
||||
} MU_XAPIAN_CATCH_BLOCK_G_ERROR(err,MU_ERROR_XAPIAN);
|
||||
|
||||
@ -36,12 +36,13 @@ typedef struct _MuStore MuStore;
|
||||
* create a new Xapian store, a place to store documents
|
||||
*
|
||||
* @param path the path to the database
|
||||
* @param err to receive error info or NULL. err->code can be found in
|
||||
* @param batchsize size of batch before committing
|
||||
* @param err to receive error info or NULL. err->code can be found in
|
||||
* mu-error.h
|
||||
*
|
||||
* @return a new MuStore object, or NULL in case of error
|
||||
*/
|
||||
MuStore* mu_store_new (const char *path, GError **err)
|
||||
MuStore* mu_store_new (const char *path, guint batchsize, GError **err)
|
||||
G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
|
||||
|
||||
|
||||
|
||||
@ -113,7 +113,7 @@ test_mu_index (void)
|
||||
xpath = g_strdup_printf ("%s%c%s", muhome, G_DIR_SEPARATOR,
|
||||
"xapian");
|
||||
|
||||
store = mu_store_new (xpath, NULL);
|
||||
store = mu_store_new (xpath, 0, NULL);
|
||||
g_assert (store);
|
||||
|
||||
g_assert_cmpuint (mu_store_count (store), ==, 4);
|
||||
|
||||
@ -42,7 +42,7 @@ test_mu_store_new_destroy (void)
|
||||
g_assert (tmpdir);
|
||||
|
||||
err = NULL;
|
||||
store = mu_store_new (tmpdir, &err);
|
||||
store = mu_store_new (tmpdir, 12345, &err);
|
||||
g_assert (store);
|
||||
g_assert (err == NULL);
|
||||
|
||||
@ -68,7 +68,7 @@ test_mu_store_version (void)
|
||||
g_assert (tmpdir);
|
||||
|
||||
err = NULL;
|
||||
store = mu_store_new (tmpdir, &err);
|
||||
store = mu_store_new (tmpdir, 789, &err);
|
||||
g_assert (store);
|
||||
g_assert (err == NULL);
|
||||
|
||||
@ -94,7 +94,7 @@ test_mu_store_store_and_count (void)
|
||||
tmpdir = test_mu_common_get_random_tmpdir();
|
||||
g_assert (tmpdir);
|
||||
|
||||
store = mu_store_new (tmpdir, NULL);
|
||||
store = mu_store_new (tmpdir, 1, NULL);
|
||||
g_assert (store);
|
||||
|
||||
g_assert_cmpuint (0,==,mu_store_count (store));
|
||||
@ -142,7 +142,7 @@ test_mu_store_store_remove_and_count (void)
|
||||
tmpdir = test_mu_common_get_random_tmpdir();
|
||||
g_assert (tmpdir);
|
||||
|
||||
store = mu_store_new (tmpdir, NULL);
|
||||
store = mu_store_new (tmpdir, 0, NULL);
|
||||
g_assert (store);
|
||||
|
||||
g_assert_cmpuint (0,==,mu_store_count (store));
|
||||
|
||||
Reference in New Issue
Block a user