# HG changeset patch # User Timo Sirainen # Date 1194291500 -7200 # Node ID 68adf46a6b3fac05fae70c8f3173229fefff236c # Parent 76c0e3a4df7a758c99b97cb936ea121d8d428a8f When adding new fields to the cache file, add all the fields we currently know about to avoid adding them one-by-one. diff -r 76c0e3a4df7a -r 68adf46a6b3f src/lib-index/mail-cache-compress.c --- a/src/lib-index/mail-cache-compress.c Mon Nov 05 21:37:27 2007 +0200 +++ b/src/lib-index/mail-cache-compress.c Mon Nov 05 21:38:20 2007 +0200 @@ -205,12 +205,19 @@ max_drop_time = idx_hdr->day_stamp == 0 ? 0 : idx_hdr->day_stamp - MAIL_CACHE_FIELD_DROP_SECS; orig_fields_count = cache->fields_count; - for (i = used_fields_count = 0; i < orig_fields_count; i++) { - if (cache->fields[i].last_used < max_drop_time) - cache->fields[i].used = FALSE; + if (cache->file_fields_count == 0) { + /* creating the initial cache file. add all fields. */ + for (i = 0; i < orig_fields_count; i++) + ctx.field_file_map[i] = i; + used_fields_count = i; + } else { + for (i = used_fields_count = 0; i < orig_fields_count; i++) { + if (cache->fields[i].last_used < max_drop_time) + cache->fields[i].used = FALSE; - ctx.field_file_map[i] = !cache->fields[i].used ? (uint32_t)-1 : - used_fields_count++; + ctx.field_file_map[i] = !cache->fields[i].used ? + (uint32_t)-1 : used_fields_count++; + } } i_array_init(ext_offsets, message_count); diff -r 76c0e3a4df7a -r 68adf46a6b3f src/lib-index/mail-cache-transaction.c --- a/src/lib-index/mail-cache-transaction.c Mon Nov 05 21:37:27 2007 +0200 +++ b/src/lib-index/mail-cache-transaction.c Mon Nov 05 21:38:20 2007 +0200 @@ -713,9 +713,16 @@ unsigned int field_idx) { struct mail_cache *cache = ctx->cache; + unsigned int i; buffer_t *buffer; int ret; + /* we want to avoid adding all the fields one by one to the cache file, + so just add all of them at once in here. the unused ones get dropped + later when compressing. */ + for (i = 0; i < cache->fields_count; i++) + cache->fields[i].used = TRUE; + if ((ret = mail_cache_transaction_lock(ctx)) <= 0) { /* create the cache file if it doesn't exist yet */ if (ctx->tried_compression) @@ -724,8 +731,10 @@ if (mail_cache_compress(cache, ctx->trans) < 0) return -1; - if ((ret = mail_cache_transaction_lock(ctx)) <= 0) - return -1; + + /* compression should have added it */ + i_assert(cache->field_file_map[field_idx] != (uint32_t)-1); + return 0; } /* re-read header to make sure we don't lose any fields. */ @@ -734,10 +743,6 @@ return -1; } - /* update these only after reading */ - cache->fields[field_idx].last_used = ioloop_time; - cache->fields[field_idx].used = TRUE; - if (cache->field_file_map[field_idx] != (uint32_t)-1) { /* it was already added */ if (mail_cache_unlock(cache) < 0) @@ -796,6 +801,9 @@ if (mail_cache_header_add_field(ctx, field_idx) < 0) return; + if (ctx->cache_file_seq == 0) + ctx->cache_file_seq = ctx->cache->hdr->file_seq; + file_field = ctx->cache->field_file_map[field_idx]; i_assert(file_field != (uint32_t)-1); }