]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: Support a small in-memory cache even with INDEX=MEMORY
authorTimo Sirainen <tss@iki.fi>
Sat, 16 Nov 2013 17:34:57 +0000 (19:34 +0200)
committerTimo Sirainen <tss@iki.fi>
Sat, 16 Nov 2013 17:34:57 +0000 (19:34 +0200)
src/lib-index/mail-cache-lookup.c
src/lib-index/mail-cache-transaction.c

index 02c3e3de7094e3df9fa14d4d92ad82f0c15fe2f1..738c68f3334aa40c485faf984d9d4954c1b16b39 100644 (file)
@@ -191,15 +191,17 @@ mail_cache_lookup_iter_next_record(struct mail_cache_lookup_iterate_ctx *ctx)
        if (ctx->offset == 0) {
                /* end of this record list. check newly appended data. */
                if (view->trans_seq1 > ctx->seq ||
-                   view->trans_seq2 < ctx->seq ||
-                   MAIL_CACHE_IS_UNUSABLE(view->cache))
+                   view->trans_seq2 < ctx->seq)
                        return 0;
-               /* check data still in memory */
+               /* check data still in memory. this works for recent mails
+                  even with INDEX=MEMORY */
                if (!ctx->memory_appends_checked) {
                        if (mail_cache_lookup_iter_transaction(ctx))
                                return 1;
                        ctx->memory_appends_checked = TRUE;
                }
+               if (MAIL_CACHE_IS_UNUSABLE(view->cache))
+                       return 0;
 
                /* check data already written to cache file */
                if (ctx->disk_appends_checked ||
index c6d96124329f92d41e752be5b5961da5ac2e8cc8..215eea612adc1b9999fe117e7e5e1c214ca0dc67 100644 (file)
@@ -592,6 +592,20 @@ static int mail_cache_header_add_field(struct mail_cache_transaction_ctx *ctx,
        struct mail_cache *cache = ctx->cache;
        int ret;
 
+       if (MAIL_INDEX_IS_IN_MEMORY(cache->index)) {
+               if (cache->file_fields_count <= field_idx) {
+                       cache->file_field_map =
+                               i_realloc(cache->file_field_map,
+                                         cache->file_fields_count *
+                                         sizeof(unsigned int),
+                                         (field_idx+1) * sizeof(unsigned int));
+                       cache->file_fields_count = field_idx+1;
+               }
+               cache->file_field_map[field_idx] = field_idx;
+               cache->field_file_map[field_idx] = field_idx;
+               return 0;
+       }
+
        if (mail_cache_transaction_lock(ctx) <= 0) {
                if (MAIL_CACHE_IS_UNUSABLE(cache))
                        return -1;
@@ -679,8 +693,12 @@ void mail_cache_add(struct mail_cache_transaction_ctx *ctx, uint32_t seq,
                if (ret < 0)
                        return;
 
-               if (ctx->cache_file_seq == 0)
-                       ctx->cache_file_seq = ctx->cache->hdr->file_seq;
+               if (ctx->cache_file_seq == 0) {
+                       if (MAIL_INDEX_IS_IN_MEMORY(ctx->cache->index))
+                               ctx->cache_file_seq = 1;
+                       else
+                               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);