Mercurial > dovecot > original-hg > dovecot-1.2
changeset 4655:df8de2e47fb5 HEAD
Delay opening the cache file until it's actually needed.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Fri, 13 Oct 2006 18:19:54 +0300 |
parents | 35d9433de1ca |
children | c27fdb8c61d6 |
files | src/lib-index/mail-cache-lookup.c src/lib-index/mail-cache-private.h src/lib-index/mail-cache.c |
diffstat | 3 files changed, 32 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-index/mail-cache-lookup.c Fri Oct 13 18:18:39 2006 +0300 +++ b/src/lib-index/mail-cache-lookup.c Fri Oct 13 18:19:54 2006 +0300 @@ -185,6 +185,9 @@ uint32_t offset; int ret; + if (!view->cache->opened) + (void)mail_cache_open_and_verify(view->cache); + if (MAIL_CACHE_IS_UNUSABLE(view->cache)) return 0; @@ -269,6 +272,9 @@ i_assert(seq > 0); i_assert(field < view->cache->fields_count); + if (!view->cache->opened) + (void)mail_cache_open_and_verify(view->cache); + file_field = view->cache->field_file_map[field]; if (file_field == (uint32_t)-1) return 0;
--- a/src/lib-index/mail-cache-private.h Fri Oct 13 18:18:39 2006 +0300 +++ b/src/lib-index/mail-cache-private.h Fri Oct 13 18:19:54 2006 +0300 @@ -147,6 +147,7 @@ unsigned int *file_field_map; unsigned int file_fields_count; + unsigned int opened:1; unsigned int locked:1; unsigned int hdr_modified:1; unsigned int field_header_write_pending:1; @@ -176,6 +177,8 @@ const void *data, size_t data_size, void *context); +int mail_cache_open_and_verify(struct mail_cache *cache); + /* Explicitly lock the cache file. Returns -1 if error, 1 if ok, 0 if we couldn't lock */ int mail_cache_lock(struct mail_cache *cache);
--- a/src/lib-index/mail-cache.c Fri Oct 13 18:18:39 2006 +0300 +++ b/src/lib-index/mail-cache.c Fri Oct 13 18:19:54 2006 +0300 @@ -251,8 +251,10 @@ return 0; } -static int mail_cache_open_and_verify(struct mail_cache *cache) +static int mail_cache_try_open(struct mail_cache *cache) { + cache->opened = TRUE; + if (MAIL_INDEX_IS_IN_MEMORY(cache->index)) return 0; @@ -273,7 +275,22 @@ if (mail_cache_map(cache, 0, sizeof(struct mail_cache_header)) < 0) return -1; - return mail_cache_header_fields_read(cache); + return 1; +} + +int mail_cache_open_and_verify(struct mail_cache *cache) +{ + int ret; + + ret = mail_cache_try_open(cache); + if (ret > 0) + ret = mail_cache_header_fields_read(cache); + if (ret < 0) { + /* failed for some reason - doesn't really matter, + it's disabled for now. */ + mail_cache_file_close(cache); + } + return ret; } static struct mail_cache *mail_cache_alloc(struct mail_index *index) @@ -323,11 +340,6 @@ struct mail_cache *cache; cache = mail_cache_alloc(index); - if (mail_cache_open_and_verify(cache) < 0) { - /* failed for some reason - doesn't really matter, - it's disabled for now. */ - mail_cache_file_close(cache); - } return cache; } @@ -336,6 +348,7 @@ struct mail_cache *cache; cache = mail_cache_alloc(index); + cache->opened = TRUE; cache->need_compress_file_seq = (uint32_t)-1; return cache; } @@ -389,6 +402,9 @@ i_assert(!cache->locked); + if (!cache->opened) + (void)mail_cache_open_and_verify(cache); + if (MAIL_CACHE_IS_UNUSABLE(cache) || MAIL_INDEX_IS_IN_MEMORY(cache->index)) return 0;