From: Timo Sirainen Date: Thu, 29 May 2008 15:49:55 +0000 (+0300) Subject: Sort index optimization: Don't write changes to sort IDs if we're doing it X-Git-Tag: 1.1.rc6~6 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f6a1fbad55980c9b257ffc1881a55dc7fafe9a83;p=thirdparty%2Fdovecot%2Fcore.git Sort index optimization: Don't write changes to sort IDs if we're doing it only to give sort ID space to expunged messages. --HG-- branch : HEAD --- diff --git a/src/lib-storage/index/index-sort-string.c b/src/lib-storage/index/index-sort-string.c index bad706ce01..f420229713 100644 --- a/src/lib-storage/index/index-sort-string.c +++ b/src/lib-storage/index/index-sort-string.c @@ -34,6 +34,7 @@ struct sort_string_context { unsigned int first_missing_sort_id_idx; uint32_t ext_id, last_seq, highest_reset_id; + uint32_t lowest_nonexpunged_zero; unsigned int regetting:1; unsigned int have_all_wanted:1; @@ -157,6 +158,14 @@ static void index_sort_node_add(struct sort_string_context *ctx, node->sort_id = 0; } else { node->sort_id = data == NULL ? 0 : *(const uint32_t *)data; + if (node->sort_id == 0) { + if (ctx->lowest_nonexpunged_zero > node->seq || + ctx->lowest_nonexpunged_zero == 0) + ctx->lowest_nonexpunged_zero = node->seq; + } else { + i_assert(ctx->lowest_nonexpunged_zero == 0 || + ctx->lowest_nonexpunged_zero > node->seq); + } } if (node->sort_id != 0) { @@ -669,6 +678,12 @@ static void index_sort_add_missing(struct sort_string_context *ctx) next_seq = seqs[i] + 1; } } + + if (ctx->lowest_nonexpunged_zero == 0) { + /* we're handling only expunged zeros. if it causes us to + renumber some existing sort IDs, don't save them. */ + ctx->no_writing = TRUE; + } } void index_sort_list_finish_string(struct mail_search_sort_program *program)