Commit fb84c2e4 authored by Richard P. Curnow's avatar Richard P. Curnow

Implement -F/--fast-index flag

For maildir and MH folders, this flag avoids doing a stat() on each message.
This should give a noticeable improvement in indexing speed when the majority
of messages are unchanged and indexing is occurring very frequently.  However,
there is a risk that mairix will not notice changes to an existing message.
However, such an omission can easily be cured by a later indexing run without
this new flag.
parent 2573eaf7
......@@ -854,7 +854,7 @@ static int do_stat(struct msgpath *mp)/*{{{*/
}
}
/*}}}*/
int update_database(struct database *db, struct msgpath *sorted_paths, int n_msgs)/*{{{*/
int update_database(struct database *db, struct msgpath *sorted_paths, int n_msgs, int do_fast_index)/*{{{*/
{
/* The incoming list must be sorted into order, to make binary searching
* possible. We search for each existing path in the incoming sorted array.
......@@ -884,18 +884,25 @@ int update_database(struct database *db, struct msgpath *sorted_paths, int n_msg
case MTY_FILE:
matched_index = lookup_msgpath(sorted_paths, n_msgs, db->msgs[i].src.mpf.path);
if (matched_index >= 0) {
status = do_stat(sorted_paths + matched_index);
if (status) {
if (sorted_paths[matched_index].src.mpf.mtime == db->msgs[i].src.mpf.mtime) {
/* Treat stale files as though the path has changed. */
file_in_db[matched_index] = 1;
file_in_new_list[i] = 1;
if (do_fast_index) {
/* Assume the presence of a matching path is good enough without
* even bothering to stat the file that's there now. */
file_in_db[matched_index] = 1;
file_in_new_list[i] = 1;
} else {
status = do_stat(sorted_paths + matched_index);
if (status) {
if (sorted_paths[matched_index].src.mpf.mtime == db->msgs[i].src.mpf.mtime) {
/* Treat stale files as though the path has changed. */
file_in_db[matched_index] = 1;
file_in_new_list[i] = 1;
} else {
fprintf(stderr, "mtime failed for '%s'\n", sorted_paths[matched_index].src.mpf.path);
}
} else {
fprintf(stderr, "mtime failed for '%s'\n", sorted_paths[matched_index].src.mpf.path);
/* This path will get treated as dead, and be re-stated below.
* When that stat fails, the path won't get added to the db. */
}
} else {
/* This path will get treated as dead, and be re-stated below.
* When that stat fails, the path won't get added to the db. */
}
}
break;
......
......@@ -473,6 +473,7 @@ int main (int argc, char **argv)/*{{{*/
int do_dump = 0;
int do_integrity_checks = 1;
int do_forced_unlock = 0;
int do_fast_index = 0;
struct globber_array *omit_globs;
......@@ -507,6 +508,9 @@ int main (int argc, char **argv)/*{{{*/
do_integrity_checks = 0;
} else if (!strcmp(*argv, "--unlock")) {
do_forced_unlock = 1;
} else if (!strcmp(*argv, "-F") ||
!strcmp(*argv, "--fast-index")) {
do_fast_index = 1;
} else if (!strcmp(*argv, "-v") || !strcmp(*argv, "--verbose")) {
verbose = 1;
} else if (!strcmp(*argv, "-V") || !strcmp(*argv, "--version")) {
......@@ -701,7 +705,7 @@ int main (int argc, char **argv)/*{{{*/
build_mbox_lists(db, folder_base, mboxen, omit_globs);
any_updates = update_database(db, msgs->paths, msgs->n);
any_updates = update_database(db, msgs->paths, msgs->n, do_fast_index);
if (do_purge) {
any_purges = cull_dead_messages(db, do_integrity_checks);
}
......
......@@ -337,7 +337,7 @@ struct database *new_database_from_file(char *db_filename, int do_integrity_chec
void free_database(struct database *db);
void maybe_grow_message_arrays(struct database *db);
void tokenise_message(int file_index, struct database *db, struct rfc822 *msg);
int update_database(struct database *db, struct msgpath *sorted_paths, int n_paths);
int update_database(struct database *db, struct msgpath *sorted_paths, int n_paths, int do_fast_index);
void check_database_integrity(struct database *db);
int cull_dead_messages(struct database *db, int do_integrity_checks);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment