Mercurial > dovecot > original-hg > dovecot-1.2
changeset 4882:969cf7a88c25 HEAD
Delay calling fts_backend_init() until first transaction is created. By that
time the mailbox has been synced and things like uidvalidity can be looked
up.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sat, 09 Dec 2006 23:08:27 +0200 |
parents | 53ac6f2c1242 |
children | d8adbe93c969 |
files | src/plugins/fts/fts-storage.c |
diffstat | 1 files changed, 27 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/src/plugins/fts/fts-storage.c Sat Dec 09 18:19:46 2006 +0200 +++ b/src/plugins/fts/fts-storage.c Sat Dec 09 23:08:27 2006 +0200 @@ -20,6 +20,9 @@ struct fts_mailbox { struct mailbox_vfuncs super; struct fts_backend *backend; + + const char *env; + unsigned int backend_failed:1; }; struct fts_search_context { @@ -45,7 +48,8 @@ struct fts_mailbox *fbox = FTS_CONTEXT(box); int ret; - fts_backend_deinit(fbox->backend); + if (fbox->backend != NULL) + fts_backend_deinit(fbox->backend); ret = fbox->super.close(box); i_free(fbox); @@ -281,6 +285,9 @@ fctx = i_new(struct fts_search_context, 1); array_idx_set(&ctx->module_contexts, fts_storage_module_id, &fctx); + if (fbox->backend == NULL) + return ctx; + /* FIXME: handle AND/OR. Maybe also header lookups? */ while (args != NULL && args->type != SEARCH_BODY && @@ -393,10 +400,12 @@ struct mail_private *mail = (struct mail_private *)_mail; struct fts_mail *fmail = FTS_CONTEXT(mail); struct fts_mailbox *fbox = FTS_CONTEXT(_mail->box); + struct fts_transaction_context *ft = FTS_CONTEXT(_mail->transaction); if (fmail->super.expunge(_mail) < 0) return -1; + ft->expunges = TRUE; fts_backend_expunge(fbox->backend, _mail); return 0; } @@ -407,21 +416,21 @@ struct mailbox_header_lookup_ctx *wanted_headers) { struct fts_mailbox *fbox = FTS_CONTEXT(t->box); - struct fts_transaction_context *ft = FTS_CONTEXT(t); struct fts_mail *fmail; struct mail *_mail; struct mail_private *mail; _mail = fbox->super.mail_alloc(t, wanted_fields, wanted_headers); - mail = (struct mail_private *)_mail; - - ft->expunges = TRUE; + if (fbox->backend != NULL) { + mail = (struct mail_private *)_mail; - fmail = p_new(mail->pool, struct fts_mail, 1); - fmail->super = mail->v; + fmail = p_new(mail->pool, struct fts_mail, 1); + fmail->super = mail->v; - mail->v.expunge = fts_mail_expunge; - array_idx_set(&mail->module_contexts, fts_storage_module_id, &fmail); + mail->v.expunge = fts_mail_expunge; + array_idx_set(&mail->module_contexts, + fts_storage_module_id, &fmail); + } return _mail; } @@ -435,6 +444,14 @@ ft = i_new(struct fts_transaction_context, 1); + /* the backend creation is delayed until the first transaction is + started. at that point the mailbox has been synced at least once. */ + if (fbox->backend == NULL && !fbox->backend_failed) { + fbox->backend = fts_backend_init(fbox->env, box); + if (fbox->backend == NULL) + fbox->backend_failed = TRUE; + } + t = fbox->super.transaction_begin(box, flags); array_idx_set(&t->module_contexts, fts_storage_module_id, &ft); return t; @@ -470,7 +487,6 @@ void fts_mailbox_opened(struct mailbox *box) { struct fts_mailbox *fbox; - struct fts_backend *backend; const char *env; if (fts_next_hook_mailbox_opened != NULL) @@ -480,13 +496,9 @@ if (env == NULL) return; - backend = fts_backend_init(env, box); - if (backend == NULL) - return; - fbox = i_new(struct fts_mailbox, 1); + fbox->env = env; fbox->super = box->v; - fbox->backend = backend; box->v.close = fts_mailbox_close; box->v.search_init = fts_mailbox_search_init; box->v.search_next_update_seq = fts_mailbox_search_next_update_seq;