* mu-store: minor changes
This commit is contained in:
@ -187,7 +187,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool in_transaction () const { return _in_transaction; }
|
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 processed () const { return _processed; }
|
||||||
int set_processed (int n) { return _processed = n;}
|
int set_processed (int n) { return _processed = n;}
|
||||||
|
|||||||
@ -49,7 +49,7 @@ _MuStore::get_uid_term (const char* path)
|
|||||||
|
|
||||||
unsigned djbhash, bkdrhash, bkdrseed;
|
unsigned djbhash, bkdrhash, bkdrseed;
|
||||||
unsigned u;
|
unsigned u;
|
||||||
static char hex[18];
|
static char hex[10];
|
||||||
|
|
||||||
djbhash = 5381;
|
djbhash = 5381;
|
||||||
bkdrhash = 0;
|
bkdrhash = 0;
|
||||||
@ -61,7 +61,9 @@ _MuStore::get_uid_term (const char* path)
|
|||||||
bkdrhash = bkdrhash * bkdrseed + path[u];
|
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;
|
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);
|
} MU_XAPIAN_CATCH_BLOCK_G_ERROR_RETURN (err, MU_ERROR_XAPIAN, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -44,7 +44,7 @@ _MuStore::begin_transaction ()
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
db_writable()->begin_transaction();
|
db_writable()->begin_transaction();
|
||||||
set_in_transaction (true);
|
in_transaction (true);
|
||||||
} MU_XAPIAN_CATCH_BLOCK;
|
} MU_XAPIAN_CATCH_BLOCK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ _MuStore::begin_transaction ()
|
|||||||
void
|
void
|
||||||
_MuStore::commit_transaction () {
|
_MuStore::commit_transaction () {
|
||||||
try {
|
try {
|
||||||
set_in_transaction (false);
|
in_transaction (false);
|
||||||
db_writable()->commit_transaction();
|
db_writable()->commit_transaction();
|
||||||
} MU_XAPIAN_CATCH_BLOCK;
|
} MU_XAPIAN_CATCH_BLOCK;
|
||||||
}
|
}
|
||||||
@ -60,7 +60,7 @@ _MuStore::commit_transaction () {
|
|||||||
void
|
void
|
||||||
_MuStore::rollback_transaction () {
|
_MuStore::rollback_transaction () {
|
||||||
try {
|
try {
|
||||||
set_in_transaction (false);
|
in_transaction (false);
|
||||||
db_writable()->cancel_transaction();
|
db_writable()->cancel_transaction();
|
||||||
} MU_XAPIAN_CATCH_BLOCK;
|
} MU_XAPIAN_CATCH_BLOCK;
|
||||||
}
|
}
|
||||||
@ -558,7 +558,7 @@ each_contact_info (MuMsgContact *contact, MsgDoc *msgdoc)
|
|||||||
|
|
||||||
|
|
||||||
Xapian::Document
|
Xapian::Document
|
||||||
doc_from_message (MuStore *store, MuMsg *msg)
|
new_doc_from_message (MuStore *store, MuMsg *msg)
|
||||||
{
|
{
|
||||||
Xapian::Document doc;
|
Xapian::Document doc;
|
||||||
MsgDoc docinfo = {&doc, msg, store};
|
MsgDoc docinfo = {&doc, msg, store};
|
||||||
@ -579,7 +579,7 @@ mu_store_add_msg (MuStore *store, MuMsg *msg, GError **err)
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
Xapian::docid id;
|
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)));
|
const std::string uid (store->get_uid_term(mu_msg_get_path(msg)));
|
||||||
|
|
||||||
if (!store->in_transaction())
|
if (!store->in_transaction())
|
||||||
@ -589,6 +589,9 @@ mu_store_add_msg (MuStore *store, MuMsg *msg, GError **err)
|
|||||||
doc.add_term (uid);
|
doc.add_term (uid);
|
||||||
id = store->db_writable()->replace_document (uid, doc);
|
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)
|
if (store->inc_processed() % store->batch_size() == 0)
|
||||||
store->commit_transaction();
|
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);
|
g_return_val_if_fail (docid != 0, MU_STORE_INVALID_DOCID);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Xapian::Document doc (doc_from_message(store, msg));
|
Xapian::Document doc (new_doc_from_message(store, msg));
|
||||||
|
|
||||||
if (!store->in_transaction())
|
if (!store->in_transaction())
|
||||||
store->begin_transaction();
|
store->begin_transaction();
|
||||||
|
|
||||||
store->db_writable()->replace_document (docid, doc);
|
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)
|
if (store->inc_processed() % store->batch_size() == 0)
|
||||||
store->commit_transaction();
|
store->commit_transaction();
|
||||||
|
|
||||||
@ -692,5 +700,3 @@ mu_store_set_timestamp (MuStore *store, const char* msgpath,
|
|||||||
sprintf (buf, "%" G_GUINT64_FORMAT, (guint64)stamp);
|
sprintf (buf, "%" G_GUINT64_FORMAT, (guint64)stamp);
|
||||||
return mu_store_set_metadata (store, msgpath, buf, err);
|
return mu_store_set_metadata (store, msgpath, buf, err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user