From 4aa838f6f6d9e489d95330688fd3702e17ce783d Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Thu, 13 Jan 2011 00:27:27 +0200 Subject: [PATCH] * mug2: implement database reindex --- src/mu-index.h | 2 +- toys/mug2/mug.cc | 44 +++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/mu-index.h b/src/mu-index.h index e2413bae..1d50f076 100644 --- a/src/mu-index.h +++ b/src/mu-index.h @@ -46,7 +46,7 @@ typedef struct _MuIndexStats MuIndexStats; * * @param xpath path to the 'homedir'; the xapian directory will be * this homedir/xapian - * + * @param batchsize for Xapian queries, or 0 for the default * @param err to receive error or NULL; there are only errors when this * function returns NULL. Possible errors: see mu-error.h * diff --git a/toys/mug2/mug.cc b/toys/mug2/mug.cc index 81e0ae2c..c40878e9 100644 --- a/toys/mug2/mug.cc +++ b/toys/mug2/mug.cc @@ -24,8 +24,9 @@ #include #include /* for memset */ -#include "mu-util.h" -#include "mu-runtime.h" +#include +#include +#include #include "mug-msg-list-view.h" #include "mug-query-bar.h" @@ -44,6 +45,43 @@ struct _MugData { }; typedef struct _MugData MugData; +MuResult +each_msg (MuIndexStats* stats, MugData *data) +{ + static int i = 0; + + if (++i % 100 == 0) + gtk_main_iteration (); + + return MU_OK; +} + +static void +reindex (MugData *mugdata) +{ + MuIndex *midx; + GError *err; + + err = NULL; + midx = mu_index_new (mu_runtime_xapian_dir(), 0, &err); + if (!midx) { + if (err && err->code == MU_ERROR_XAPIAN_CANNOT_GET_WRITELOCK) { + g_warning ("database busy..."); + return; /* db already busy.. */ + } + g_warning ("failed to get index: %s", err ? err->message : ""); + g_error_free (err); + return; + } + + mu_index_run (midx, + mu_index_last_used_maildir(midx), + FALSE, NULL, (MuIndexMsgCallback)each_msg, NULL, mugdata); + + mu_index_destroy (midx); +} + + static void about_mug (MugData * mugdata) { @@ -90,7 +128,7 @@ on_tool_button_clicked (GtkToolButton * btn, MugData * mugdata) (mugdata->mlist)); break; case ACTION_REINDEX: - g_print ("Reindex!\n"); + reindex (mugdata); break; case ACTION_ABOUT: about_mug (mugdata);