* mu-store: minor changes

This commit is contained in:
Dirk-Jan C. Binnema 2011-10-10 08:37:37 +03:00
parent 41a8ae3124
commit c16496817d
3 changed files with 19 additions and 13 deletions

View File

@ -187,7 +187,7 @@ public:
}
bool in_transaction () const { return _in_transaction; }
bool set_in_transaction (bool in_tx) { return _in_transaction = in_tx; }
bool in_transaction (bool in_tx) { return _in_transaction = in_tx; }
int processed () const { return _processed; }
int set_processed (int n) { return _processed = n;}

View File

@ -49,7 +49,7 @@ _MuStore::get_uid_term (const char* path)
unsigned djbhash, bkdrhash, bkdrseed;
unsigned u;
static char hex[18];
static char hex[10];
djbhash = 5381;
bkdrhash = 0;
@ -61,7 +61,9 @@ _MuStore::get_uid_term (const char* path)
bkdrhash = bkdrhash * bkdrseed + path[u];
}
sprintf (hex, MU_STORE_UID_PREFIX "%08x%08x", djbhash, bkdrhash);
snprintf (hex, sizeof(hex),
MU_STORE_UID_PREFIX "%04x%04x",
djbhash, bkdrhash);
return hex;
}
@ -262,5 +264,3 @@ mu_store_get_msg (MuStore *self, unsigned docid, GError **err)
} MU_XAPIAN_CATCH_BLOCK_G_ERROR_RETURN (err, MU_ERROR_XAPIAN, 0);
}

View File

@ -44,7 +44,7 @@ _MuStore::begin_transaction ()
{
try {
db_writable()->begin_transaction();
set_in_transaction (true);
in_transaction (true);
} MU_XAPIAN_CATCH_BLOCK;
}
@ -52,7 +52,7 @@ _MuStore::begin_transaction ()
void
_MuStore::commit_transaction () {
try {
set_in_transaction (false);
in_transaction (false);
db_writable()->commit_transaction();
} MU_XAPIAN_CATCH_BLOCK;
}
@ -60,7 +60,7 @@ _MuStore::commit_transaction () {
void
_MuStore::rollback_transaction () {
try {
set_in_transaction (false);
in_transaction (false);
db_writable()->cancel_transaction();
} MU_XAPIAN_CATCH_BLOCK;
}
@ -558,7 +558,7 @@ each_contact_info (MuMsgContact *contact, MsgDoc *msgdoc)
Xapian::Document
doc_from_message (MuStore *store, MuMsg *msg)
new_doc_from_message (MuStore *store, MuMsg *msg)
{
Xapian::Document doc;
MsgDoc docinfo = {&doc, msg, store};
@ -579,7 +579,7 @@ mu_store_add_msg (MuStore *store, MuMsg *msg, GError **err)
try {
Xapian::docid id;
Xapian::Document doc (doc_from_message(store, msg));
Xapian::Document doc (new_doc_from_message(store, msg));
const std::string uid (store->get_uid_term(mu_msg_get_path(msg)));
if (!store->in_transaction())
@ -589,6 +589,9 @@ mu_store_add_msg (MuStore *store, MuMsg *msg, GError **err)
doc.add_term (uid);
id = store->db_writable()->replace_document (uid, doc);
MU_WRITE_LOG ("add %s (%s)",
mu_msg_get_path (msg), uid.c_str());
if (store->inc_processed() % store->batch_size() == 0)
store->commit_transaction();
@ -611,13 +614,18 @@ mu_store_update_msg (MuStore *store, unsigned docid, MuMsg *msg, GError **err)
g_return_val_if_fail (docid != 0, MU_STORE_INVALID_DOCID);
try {
Xapian::Document doc (doc_from_message(store, msg));
Xapian::Document doc (new_doc_from_message(store, msg));
if (!store->in_transaction())
store->begin_transaction();
store->db_writable()->replace_document (docid, doc);
MU_WRITE_LOG ("update %s (%s) %u",
mu_msg_get_path (msg),
store->get_uid_term(mu_msg_get_path(msg)),
docid);
if (store->inc_processed() % store->batch_size() == 0)
store->commit_transaction();
@ -692,5 +700,3 @@ mu_store_set_timestamp (MuStore *store, const char* msgpath,
sprintf (buf, "%" G_GUINT64_FORMAT, (guint64)stamp);
return mu_store_set_metadata (store, msgpath, buf, err);
}