mirror of
https://git.notmuchmail.org/git/notmuch
synced 2025-02-17 23:53:15 +01:00
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.
This commit is contained in:
parent
ccf2e0cc42
commit
c340c1bd11
3 changed files with 37 additions and 32 deletions
|
@ -681,8 +681,7 @@ handle_sigalrm (unused (int signal))
|
||||||
notmuch_status_t
|
notmuch_status_t
|
||||||
notmuch_database_upgrade (notmuch_database_t *notmuch,
|
notmuch_database_upgrade (notmuch_database_t *notmuch,
|
||||||
void (*progress_notify) (void *closure,
|
void (*progress_notify) (void *closure,
|
||||||
unsigned int count,
|
double progress),
|
||||||
unsigned int total),
|
|
||||||
void *closure)
|
void *closure)
|
||||||
{
|
{
|
||||||
Xapian::WritableDatabase *db;
|
Xapian::WritableDatabase *db;
|
||||||
|
@ -691,6 +690,7 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
|
||||||
notmuch_bool_t timer_is_active = FALSE;
|
notmuch_bool_t timer_is_active = FALSE;
|
||||||
unsigned int version;
|
unsigned int version;
|
||||||
notmuch_status_t status;
|
notmuch_status_t status;
|
||||||
|
unsigned int count = 0, total = 0;
|
||||||
|
|
||||||
status = _notmuch_database_ensure_writable (notmuch);
|
status = _notmuch_database_ensure_writable (notmuch);
|
||||||
if (status)
|
if (status)
|
||||||
|
@ -726,11 +726,11 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
|
||||||
* notmuch_message_add_filename.
|
* notmuch_message_add_filename.
|
||||||
*/
|
*/
|
||||||
if (version < 1) {
|
if (version < 1) {
|
||||||
unsigned int count = 0, total;
|
|
||||||
notmuch_query_t *query = notmuch_query_create (notmuch, "");
|
notmuch_query_t *query = notmuch_query_create (notmuch, "");
|
||||||
notmuch_messages_t *messages;
|
notmuch_messages_t *messages;
|
||||||
notmuch_message_t *message;
|
notmuch_message_t *message;
|
||||||
char *filename;
|
char *filename;
|
||||||
|
Xapian::TermIterator t, t_end;
|
||||||
|
|
||||||
total = notmuch_query_count_messages (query);
|
total = notmuch_query_count_messages (query);
|
||||||
|
|
||||||
|
@ -739,7 +739,7 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
|
||||||
notmuch_messages_advance (messages))
|
notmuch_messages_advance (messages))
|
||||||
{
|
{
|
||||||
if (do_progress_notify) {
|
if (do_progress_notify) {
|
||||||
progress_notify (closure, count, total);
|
progress_notify (closure, (double) count / total);
|
||||||
do_progress_notify = 0;
|
do_progress_notify = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -758,13 +758,10 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
|
||||||
}
|
}
|
||||||
|
|
||||||
notmuch_query_destroy (query);
|
notmuch_query_destroy (query);
|
||||||
}
|
|
||||||
|
|
||||||
/* Also, before version 1 we stored directory timestamps in
|
/* Also, before version 1 we stored directory timestamps in
|
||||||
* XTIMESTAMP documents instead of the current XDIRECTORY
|
* XTIMESTAMP documents instead of the current XDIRECTORY
|
||||||
* documents. So copy those as well. */
|
* documents. So copy those as well. */
|
||||||
if (version < 1) {
|
|
||||||
Xapian::TermIterator t, t_end;
|
|
||||||
|
|
||||||
t_end = notmuch->xapian_db->allterms_end ("XTIMESTAMP");
|
t_end = notmuch->xapian_db->allterms_end ("XTIMESTAMP");
|
||||||
|
|
||||||
|
@ -785,6 +782,11 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
|
||||||
time_t mtime;
|
time_t mtime;
|
||||||
notmuch_directory_t *directory;
|
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);
|
document = find_document_for_doc_id (notmuch, *p);
|
||||||
mtime = Xapian::sortable_unserialise (
|
mtime = Xapian::sortable_unserialise (
|
||||||
document.get_value (NOTMUCH_VALUE_TIMESTAMP));
|
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
|
/* Now that the upgrade is complete we can remove the old data
|
||||||
* and documents that are no longer needed. */
|
* and documents that are no longer needed. */
|
||||||
if (version < 1) {
|
if (version < 1) {
|
||||||
unsigned int count = 0, total;
|
|
||||||
notmuch_query_t *query = notmuch_query_create (notmuch, "");
|
notmuch_query_t *query = notmuch_query_create (notmuch, "");
|
||||||
notmuch_messages_t *messages;
|
notmuch_messages_t *messages;
|
||||||
notmuch_message_t *message;
|
notmuch_message_t *message;
|
||||||
char *filename;
|
char *filename;
|
||||||
|
|
||||||
total = notmuch_query_count_messages (query);
|
|
||||||
|
|
||||||
for (messages = notmuch_query_search_messages (query);
|
for (messages = notmuch_query_search_messages (query);
|
||||||
notmuch_messages_has_more (messages);
|
notmuch_messages_has_more (messages);
|
||||||
notmuch_messages_advance (messages))
|
notmuch_messages_advance (messages))
|
||||||
{
|
{
|
||||||
if (do_progress_notify) {
|
if (do_progress_notify) {
|
||||||
progress_notify (closure, count, total);
|
progress_notify (closure, (double) count / total);
|
||||||
do_progress_notify = 0;
|
do_progress_notify = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -830,8 +829,6 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
|
||||||
talloc_free (filename);
|
talloc_free (filename);
|
||||||
|
|
||||||
notmuch_message_destroy (message);
|
notmuch_message_destroy (message);
|
||||||
|
|
||||||
count++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
notmuch_query_destroy (query);
|
notmuch_query_destroy (query);
|
||||||
|
@ -855,6 +852,11 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
|
||||||
p != p_end;
|
p != p_end;
|
||||||
p++)
|
p++)
|
||||||
{
|
{
|
||||||
|
if (do_progress_notify) {
|
||||||
|
progress_notify (closure, (double) count / total);
|
||||||
|
do_progress_notify = 0;
|
||||||
|
}
|
||||||
|
|
||||||
db->delete_document (*p);
|
db->delete_document (*p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -204,15 +204,14 @@ notmuch_database_needs_upgrade (notmuch_database_t *database);
|
||||||
*
|
*
|
||||||
* The optional progress_notify callback can be used by the caller to
|
* The optional progress_notify callback can be used by the caller to
|
||||||
* provide progress indication to the user. If non-NULL it will be
|
* provide progress indication to the user. If non-NULL it will be
|
||||||
* called periodically with 'count' as the number of messages upgraded
|
* called periodically with 'progress' as a floating-point value in
|
||||||
* so far and 'total' the overall number of messages that will be
|
* the range of [0.0 .. 1.0] indicating the progress made so far in
|
||||||
* converted.
|
* the upgrade process.
|
||||||
*/
|
*/
|
||||||
notmuch_status_t
|
notmuch_status_t
|
||||||
notmuch_database_upgrade (notmuch_database_t *database,
|
notmuch_database_upgrade (notmuch_database_t *database,
|
||||||
void (*progress_notify) (void *closure,
|
void (*progress_notify) (void *closure,
|
||||||
unsigned int count,
|
double progress),
|
||||||
unsigned int total),
|
|
||||||
void *closure);
|
void *closure);
|
||||||
|
|
||||||
/* Retrieve a directory object from the database for 'path'.
|
/* Retrieve a directory object from the database for 'path'.
|
||||||
|
|
|
@ -618,22 +618,26 @@ count_files (const char *path, int *count)
|
||||||
|
|
||||||
static void
|
static void
|
||||||
upgrade_print_progress (void *closure,
|
upgrade_print_progress (void *closure,
|
||||||
unsigned int count,
|
double progress)
|
||||||
unsigned int total)
|
|
||||||
{
|
{
|
||||||
add_files_state_t *state = closure;
|
add_files_state_t *state = closure;
|
||||||
|
|
||||||
|
printf ("Upgrading database: %.2f%% complete", progress * 100.0);
|
||||||
|
|
||||||
|
if (progress > 0) {
|
||||||
struct timeval tv_now;
|
struct timeval tv_now;
|
||||||
double elapsed_overall, rate_overall, time_remaining;
|
double elapsed, time_remaining;
|
||||||
|
|
||||||
gettimeofday (&tv_now, NULL);
|
gettimeofday (&tv_now, NULL);
|
||||||
|
|
||||||
elapsed_overall = notmuch_time_elapsed (state->tv_start, tv_now);
|
elapsed = notmuch_time_elapsed (state->tv_start, tv_now);
|
||||||
rate_overall = count / elapsed_overall;
|
time_remaining = (elapsed / progress) * (1.0 - progress);
|
||||||
time_remaining = ((total - count) / rate_overall);
|
printf (" (");
|
||||||
|
|
||||||
printf ("Upgraded %d of %d messages (", count, total);
|
|
||||||
notmuch_time_print_formatted_seconds (time_remaining);
|
notmuch_time_print_formatted_seconds (time_remaining);
|
||||||
printf (" remaining). \r");
|
printf (" remaining)");
|
||||||
|
}
|
||||||
|
|
||||||
|
printf (". \r");
|
||||||
|
|
||||||
fflush (stdout);
|
fflush (stdout);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue