[dovecot-cvs] dovecot/src/lib-storage/index Makefile.am, 1.15,
1.16 index-mail.c, 1.99, 1.100 index-search.c, 1.113,
1.114 index-sort.c, 1.11, 1.12 index-sort.h, 1.6,
1.7 index-storage.h, 1.101, 1.102
tss-movial at dovecot.org
tss-movial at dovecot.org
Thu Jun 8 15:49:39 EEST 2006
Update of /var/lib/cvs/dovecot/src/lib-storage/index
In directory talvi:/tmp/cvs-serv22007/lib-storage/index
Modified Files:
Makefile.am index-mail.c index-search.c index-storage.h
Added Files:
index-sort.c index-sort.h
Log Message:
Changed mail-storage API to do the mail sorting internally. Optimized it
internally to keep a 32bit sort_id field in index for each used primary sort
condition. Practically this should mean less disk I/O, memory and CPU usage
when SORT command is used.
Index: Makefile.am
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/Makefile.am,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- Makefile.am 27 Nov 2005 23:05:28 -0000 1.15
+++ Makefile.am 8 Jun 2006 12:49:37 -0000 1.16
@@ -15,6 +15,7 @@
index-mail-headers.c \
index-mailbox-check.c \
index-search.c \
+ index-sort.c \
index-status.c \
index-storage.c \
index-sync.c \
@@ -22,4 +23,5 @@
noinst_HEADERS = \
index-mail.h \
+ index-sort.h \
index-storage.h
Index: index-mail.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/index-mail.c,v
retrieving revision 1.99
retrieving revision 1.100
diff -u -d -r1.99 -r1.100
--- index-mail.c 16 May 2006 09:10:31 -0000 1.99
+++ index-mail.c 8 Jun 2006 12:49:37 -0000 1.100
@@ -873,6 +873,9 @@
struct mail_cache_view *cache_view = mail->trans->cache_view;
const struct mail_index_record *rec;
+ if (data->seq == seq)
+ return 0;
+
if (mail_index_lookup(mail->trans->trans_view, seq, &rec) < 0) {
mail_storage_set_index_error(mail->ibox);
return -1;
Index: index-search.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/index-search.c,v
retrieving revision 1.113
retrieving revision 1.114
diff -u -d -r1.113 -r1.114
--- index-search.c 8 May 2006 08:46:22 -0000 1.113
+++ index-search.c 8 Jun 2006 12:49:37 -0000 1.114
@@ -1,4 +1,4 @@
-/* Copyright (C) 2002 Timo Sirainen */
+/* Copyright (C) 2002-2006 Timo Sirainen */
#include "lib.h"
#include "istream.h"
@@ -11,6 +11,7 @@
#include "imap-date.h"
#include "index-storage.h"
#include "index-mail.h"
+#include "index-sort.h"
#include "mail-search.h"
#include <stdlib.h>
@@ -25,6 +26,7 @@
struct index_mailbox *ibox;
char *charset;
struct mail_search_arg *args;
+ struct mail_search_sort_program *sort_program;
uint32_t seq1, seq2;
struct mail *mail;
@@ -34,6 +36,7 @@
const char *error;
unsigned int failed:1;
+ unsigned int sorted:1;
unsigned int have_seqsets:1;
};
@@ -764,14 +767,6 @@
return 0;
}
-int index_storage_search_get_sorting(struct mailbox *box __attr_unused__,
- enum mail_sort_type *sort_program)
-{
- /* currently we don't support sorting */
- *sort_program = MAIL_SORT_END;
- return 0;
-}
-
struct mail_search_context *
index_storage_search_init(struct mailbox_transaction_context *_t,
const char *charset, struct mail_search_arg *args,
@@ -781,17 +776,13 @@
(struct index_transaction_context *)_t;
struct index_search_context *ctx;
- if (sort_program != NULL && *sort_program != MAIL_SORT_END) {
- i_fatal("BUG: index_storage_search_init(): "
- "invalid sort_program");
- }
-
ctx = i_new(struct index_search_context, 1);
ctx->mail_ctx.transaction = _t;
ctx->ibox = t->ibox;
ctx->view = t->trans_view;
ctx->charset = i_strdup(charset);
ctx->args = args;
+ ctx->sort_program = index_sort_program_init(_t, sort_program);
mail_search_args_reset(ctx->args, TRUE);
@@ -823,6 +814,8 @@
if (ctx->hdr_pool != NULL)
pool_unref(ctx->hdr_pool);
+ if (ctx->sort_program != NULL)
+ index_sort_program_deinit(&ctx->sort_program);
i_free(ctx->charset);
i_free(ctx);
return ret;
@@ -868,6 +861,9 @@
struct mailbox *box = _ctx->transaction->box;
int ret;
+ if (ctx->sorted)
+ return index_sort_list_next(ctx->sort_program, mail);
+
ctx->mail = mail;
ctx->imail = (struct index_mail *)mail;
@@ -885,14 +881,28 @@
if (ctx->error != NULL)
ret = -1;
- if (ret != 0)
- break;
+ if (ret != 0) {
+ if (ctx->sort_program == NULL)
+ break;
+
+ if (index_sort_list_add(ctx->sort_program, mail) < 0) {
+ ret = -1;
+ break;
+ }
+ }
}
if (ret < 0)
ctx->failed = TRUE;
ctx->mail = NULL;
ctx->imail = NULL;
+ if (ctx->sort_program != NULL && ret == 0) {
+ ctx->sorted = TRUE;
+ if (index_sort_list_finish(ctx->sort_program) < 0)
+ return -1;
+ return index_sort_list_next(ctx->sort_program, mail);
+ }
+
return ret;
}
Index: index-storage.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/index-storage.h,v
retrieving revision 1.101
retrieving revision 1.102
diff -u -d -r1.101 -r1.102
--- index-storage.h 14 Apr 2006 12:30:21 -0000 1.101
+++ index-storage.h 8 Jun 2006 12:49:37 -0000 1.102
@@ -168,8 +168,6 @@
index_header_lookup_init(struct mailbox *box, const char *const headers[]);
void index_header_lookup_deinit(struct mailbox_header_lookup_ctx *ctx);
-int index_storage_search_get_sorting(struct mailbox *box,
- enum mail_sort_type *sort_program);
struct mail_search_context *
index_storage_search_init(struct mailbox_transaction_context *t,
const char *charset, struct mail_search_arg *args,
More information about the dovecot-cvs
mailing list