aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/database.cc
diff options
context:
space:
mode:
authorGravatar Carl Worth <cworth@cworth.org>2010-01-09 17:38:23 -0800
committerGravatar Carl Worth <cworth@cworth.org>2010-01-09 17:38:23 -0800
commitc340c1bd1140c0a1b7e0f24ef3ebac806f5fc3e6 (patch)
treef9b2fa23adbe5b62812a87327704d141fe7247fc /lib/database.cc
parentccf2e0cc4211c276da1db43cdca7ee11018c391d (diff)
notmuch new: Print upgrade progress report as a percentage.
Previously we were printing a number of messages upgraded so far. The original motivation for this was to accurately reflect the fact that there are two passes, (so each message is processed twice and it's not accurate to represent with a single count). But as it turns out, the second pass takes zero time (relatively speaking) so we're still not accounting for it. If nothing else, the percentage-based reporting makes for a cleaner API for the progress_notify function.
Diffstat (limited to 'lib/database.cc')
-rw-r--r--lib/database.cc34
1 files changed, 18 insertions, 16 deletions
diff --git a/lib/database.cc b/lib/database.cc
index 19f960e2..cce78478 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -681,8 +681,7 @@ handle_sigalrm (unused (int signal))
notmuch_status_t
notmuch_database_upgrade (notmuch_database_t *notmuch,
void (*progress_notify) (void *closure,
- unsigned int count,
- unsigned int total),
+ double progress),
void *closure)
{
Xapian::WritableDatabase *db;
@@ -691,6 +690,7 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
notmuch_bool_t timer_is_active = FALSE;
unsigned int version;
notmuch_status_t status;
+ unsigned int count = 0, total = 0;
status = _notmuch_database_ensure_writable (notmuch);
if (status)
@@ -726,11 +726,11 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
* notmuch_message_add_filename.
*/
if (version < 1) {
- unsigned int count = 0, total;
notmuch_query_t *query = notmuch_query_create (notmuch, "");
notmuch_messages_t *messages;
notmuch_message_t *message;
char *filename;
+ Xapian::TermIterator t, t_end;
total = notmuch_query_count_messages (query);
@@ -739,7 +739,7 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
notmuch_messages_advance (messages))
{
if (do_progress_notify) {
- progress_notify (closure, count, total);
+ progress_notify (closure, (double) count / total);
do_progress_notify = 0;
}
@@ -758,13 +758,10 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
}
notmuch_query_destroy (query);
- }
- /* Also, before version 1 we stored directory timestamps in
- * XTIMESTAMP documents instead of the current XDIRECTORY
- * documents. So copy those as well. */
- if (version < 1) {
- Xapian::TermIterator t, t_end;
+ /* Also, before version 1 we stored directory timestamps in
+ * XTIMESTAMP documents instead of the current XDIRECTORY
+ * documents. So copy those as well. */
t_end = notmuch->xapian_db->allterms_end ("XTIMESTAMP");
@@ -785,6 +782,11 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
time_t mtime;
notmuch_directory_t *directory;
+ if (do_progress_notify) {
+ progress_notify (closure, (double) count / total);
+ do_progress_notify = 0;
+ }
+
document = find_document_for_doc_id (notmuch, *p);
mtime = Xapian::sortable_unserialise (
document.get_value (NOTMUCH_VALUE_TIMESTAMP));
@@ -803,20 +805,17 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
/* Now that the upgrade is complete we can remove the old data
* and documents that are no longer needed. */
if (version < 1) {
- unsigned int count = 0, total;
notmuch_query_t *query = notmuch_query_create (notmuch, "");
notmuch_messages_t *messages;
notmuch_message_t *message;
char *filename;
- total = notmuch_query_count_messages (query);
-
for (messages = notmuch_query_search_messages (query);
notmuch_messages_has_more (messages);
notmuch_messages_advance (messages))
{
if (do_progress_notify) {
- progress_notify (closure, count, total);
+ progress_notify (closure, (double) count / total);
do_progress_notify = 0;
}
@@ -830,8 +829,6 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
talloc_free (filename);
notmuch_message_destroy (message);
-
- count++;
}
notmuch_query_destroy (query);
@@ -855,6 +852,11 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
p != p_end;
p++)
{
+ if (do_progress_notify) {
+ progress_notify (closure, (double) count / total);
+ do_progress_notify = 0;
+ }
+
db->delete_document (*p);
}
}