From: Timo Sirainen Date: Thu, 14 Oct 2021 14:33:30 +0000 (+0300) Subject: lib-storage: Move search matching into mailbox_vfuncs.search_next_match_mail() X-Git-Tag: 2.3.18~181 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=356b36fc525432e482751082a7093aeba769b199;p=thirdparty%2Fdovecot%2Fcore.git lib-storage: Move search matching into mailbox_vfuncs.search_next_match_mail() --- diff --git a/src/lib-storage/fail-mailbox.c b/src/lib-storage/fail-mailbox.c index 3c4ea91a66..7925c93692 100644 --- a/src/lib-storage/fail-mailbox.c +++ b/src/lib-storage/fail-mailbox.c @@ -211,6 +211,13 @@ fail_mailbox_search_next_update_seq(struct mail_search_context *ctx ATTR_UNUSED) return FALSE; } +static int +fail_mailbox_search_next_match_mail(struct mail_search_context *ctx ATTR_UNUSED, + struct mail *mail ATTR_UNUSED) +{ + return -1; +} + static struct mail_save_context * fail_mailbox_save_alloc(struct mailbox_transaction_context *t) { @@ -293,6 +300,7 @@ struct mailbox fail_mailbox = { fail_mailbox_search_deinit, fail_mailbox_search_next_nonblock, fail_mailbox_search_next_update_seq, + fail_mailbox_search_next_match_mail, fail_mailbox_save_alloc, fail_mailbox_save_begin, fail_mailbox_save_continue, diff --git a/src/lib-storage/index/dbox-multi/mdbox-deleted-storage.c b/src/lib-storage/index/dbox-multi/mdbox-deleted-storage.c index b3ffe3e5c8..4fdf1ab2cf 100644 --- a/src/lib-storage/index/dbox-multi/mdbox-deleted-storage.c +++ b/src/lib-storage/index/dbox-multi/mdbox-deleted-storage.c @@ -294,6 +294,7 @@ struct mailbox mdbox_deleted_mailbox = { index_storage_search_deinit, index_storage_search_next_nonblock, index_storage_search_next_update_seq, + index_storage_search_next_match_mail, mdbox_deleted_save_alloc, mdbox_deleted_save_begin, mdbox_deleted_save_continue, diff --git a/src/lib-storage/index/dbox-multi/mdbox-storage.c b/src/lib-storage/index/dbox-multi/mdbox-storage.c index eff2a27cc4..e7e7f600e5 100644 --- a/src/lib-storage/index/dbox-multi/mdbox-storage.c +++ b/src/lib-storage/index/dbox-multi/mdbox-storage.c @@ -505,6 +505,7 @@ struct mailbox mdbox_mailbox = { index_storage_search_deinit, index_storage_search_next_nonblock, index_storage_search_next_update_seq, + index_storage_search_next_match_mail, mdbox_save_alloc, mdbox_save_begin, dbox_save_continue, diff --git a/src/lib-storage/index/dbox-single/sdbox-storage.c b/src/lib-storage/index/dbox-single/sdbox-storage.c index e43421cb59..5a6fcaddec 100644 --- a/src/lib-storage/index/dbox-single/sdbox-storage.c +++ b/src/lib-storage/index/dbox-single/sdbox-storage.c @@ -509,6 +509,7 @@ struct mailbox sdbox_mailbox = { index_storage_search_deinit, index_storage_search_next_nonblock, index_storage_search_next_update_seq, + index_storage_search_next_match_mail, sdbox_save_alloc, sdbox_save_begin, dbox_save_continue, diff --git a/src/lib-storage/index/imapc/imapc-storage.c b/src/lib-storage/index/imapc/imapc-storage.c index 71d9bb768d..49bf78f7e4 100644 --- a/src/lib-storage/index/imapc/imapc-storage.c +++ b/src/lib-storage/index/imapc/imapc-storage.c @@ -1307,6 +1307,7 @@ struct mailbox imapc_mailbox = { imapc_search_deinit, index_storage_search_next_nonblock, imapc_search_next_update_seq, + index_storage_search_next_match_mail, imapc_save_alloc, imapc_save_begin, imapc_save_continue, diff --git a/src/lib-storage/index/index-search.c b/src/lib-storage/index/index-search.c index 1e1caaefe9..ab20efaeaf 100644 --- a/src/lib-storage/index/index-search.c +++ b/src/lib-storage/index/index-search.c @@ -1601,14 +1601,61 @@ static bool search_would_block(struct index_search_context *ctx) return ret; } +int index_storage_search_next_match_mail(struct mail_search_context *_ctx, + struct mail *mail) +{ + struct index_search_context *ctx = + container_of(_ctx, struct index_search_context, mail_ctx); + struct index_mail *imail = INDEX_MAIL(mail); + int match; + + ctx->cur_mail = mail; + /* mail's access_type is SEARCH only while using it to process + the search query. afterwards the mail can still be accessed + for fetching. */ + ctx->cur_mail->access_type = MAIL_ACCESS_TYPE_SEARCH; + T_BEGIN { + match = search_match_next(ctx); + } T_END; + ctx->cur_mail->access_type = MAIL_ACCESS_TYPE_DEFAULT; + ctx->cur_mail = NULL; + + i_assert(imail->data.search_results == NULL); + if (match < 0) { + /* result isn't known yet, do a prefetch and + finish later */ + imail->data.search_results = + buffer_create_dynamic(imail->mail.data_pool, 64); + mail_search_args_result_serialize(_ctx->args, + imail->data.search_results); + } + + mail_search_args_reset(_ctx->args->args, FALSE); + + if (match != 0) { + /* either matched or result is still unknown. + anyway we're far enough now that we probably want + to update the access_parts. the only problem here is + if searching would want fewer access_parts than the + fetching part, but that's probably not a big problem + usually. */ + index_mail_update_access_parts_pre(mail); + return 1; + } + + /* non-match */ + if (_ctx->args->stop_on_nonmatch) + return -1; + return 0; +} + static int search_more_with_mail(struct index_search_context *ctx, struct mail *mail) { struct mail_search_context *_ctx = &ctx->mail_ctx; struct mailbox *box = _ctx->transaction->box; - struct index_mail *imail = INDEX_MAIL(mail); unsigned long long cost1, cost2; - int match, ret; + int ret; if (search_would_block(ctx)) { /* this lookup is useful when a large number of @@ -1627,55 +1674,17 @@ static int search_more_with_mail(struct index_search_context *ctx, while (box->v.search_next_update_seq(_ctx)) { mail_set_seq(mail, _ctx->seq); - ctx->cur_mail = mail; - /* mail's access_type is SEARCH only while using it to process - the search query. afterwards the mail can still be accessed - for fetching. */ - ctx->cur_mail->access_type = MAIL_ACCESS_TYPE_SEARCH; - T_BEGIN { - match = search_match_next(ctx); - } T_END; - ctx->cur_mail->access_type = MAIL_ACCESS_TYPE_DEFAULT; - ctx->cur_mail = NULL; - - i_assert(imail->data.search_results == NULL); - if (match < 0) { - /* result isn't known yet, do a prefetch and - finish later */ - imail->data.search_results = - buffer_create_dynamic(imail->mail.data_pool, 64); - mail_search_args_result_serialize(_ctx->args, - imail->data.search_results); - } - - mail_search_args_reset(_ctx->args->args, FALSE); - - if (match != 0) { - /* either matched or result is still unknown. - anyway we're far enough now that we probably want - to update the access_parts. the only problem here is - if searching would want fewer access_parts than the - fetching part, but that's probably not a big problem - usually. */ - index_mail_update_access_parts_pre(mail); - ret = 1; - break; - } - - /* non-match */ - if (_ctx->args->stop_on_nonmatch) { - ret = -1; + ret = box->v.search_next_match_mail(_ctx, mail); + if (ret != 0) break; - } cost2 = search_get_cost(mail->transaction); ctx->cost += cost2 - cost1; cost1 = cost2; - if (search_would_block(ctx)) { - ret = 0; + if (search_would_block(ctx)) break; - } + ret = -1; } cost2 = search_get_cost(mail->transaction); ctx->cost += cost2 - cost1; diff --git a/src/lib-storage/index/index-storage.h b/src/lib-storage/index/index-storage.h index dd26b3d372..43e7d24d6f 100644 --- a/src/lib-storage/index/index-storage.h +++ b/src/lib-storage/index/index-storage.h @@ -142,6 +142,8 @@ int index_storage_search_deinit(struct mail_search_context *ctx); bool index_storage_search_next_nonblock(struct mail_search_context *ctx, struct mail **mail_r, bool *tryagain_r); bool index_storage_search_next_update_seq(struct mail_search_context *ctx); +int index_storage_search_next_match_mail(struct mail_search_context *ctx, + struct mail *mail); struct mailbox_transaction_context * index_transaction_begin(struct mailbox *box, diff --git a/src/lib-storage/index/maildir/maildir-storage.c b/src/lib-storage/index/maildir/maildir-storage.c index f9c5a80cdc..e65579ff1f 100644 --- a/src/lib-storage/index/maildir/maildir-storage.c +++ b/src/lib-storage/index/maildir/maildir-storage.c @@ -734,6 +734,7 @@ struct mailbox maildir_mailbox = { index_storage_search_deinit, index_storage_search_next_nonblock, index_storage_search_next_update_seq, + index_storage_search_next_match_mail, maildir_save_alloc, maildir_save_begin, maildir_save_continue, diff --git a/src/lib-storage/index/mbox/mbox-storage.c b/src/lib-storage/index/mbox/mbox-storage.c index 2e8eae4b70..4b2bb359f9 100644 --- a/src/lib-storage/index/mbox/mbox-storage.c +++ b/src/lib-storage/index/mbox/mbox-storage.c @@ -896,6 +896,7 @@ struct mailbox mbox_mailbox = { index_storage_search_deinit, index_storage_search_next_nonblock, index_storage_search_next_update_seq, + index_storage_search_next_match_mail, mbox_save_alloc, mbox_save_begin, mbox_save_continue, diff --git a/src/lib-storage/index/pop3c/pop3c-storage.c b/src/lib-storage/index/pop3c/pop3c-storage.c index e6e3d1dcc4..f7846836e8 100644 --- a/src/lib-storage/index/pop3c/pop3c-storage.c +++ b/src/lib-storage/index/pop3c/pop3c-storage.c @@ -353,6 +353,7 @@ struct mailbox pop3c_mailbox = { index_storage_search_deinit, index_storage_search_next_nonblock, index_storage_search_next_update_seq, + index_storage_search_next_match_mail, pop3c_save_alloc, pop3c_save_begin, pop3c_save_continue, diff --git a/src/lib-storage/index/raw/raw-storage.c b/src/lib-storage/index/raw/raw-storage.c index cb95fdaa2e..32883635c5 100644 --- a/src/lib-storage/index/raw/raw-storage.c +++ b/src/lib-storage/index/raw/raw-storage.c @@ -254,6 +254,7 @@ struct mailbox raw_mailbox = { index_storage_search_deinit, index_storage_search_next_nonblock, index_storage_search_next_update_seq, + index_storage_search_next_match_mail, NULL, NULL, NULL, diff --git a/src/lib-storage/mail-storage-private.h b/src/lib-storage/mail-storage-private.h index 9537a5b6de..8a419030a0 100644 --- a/src/lib-storage/mail-storage-private.h +++ b/src/lib-storage/mail-storage-private.h @@ -312,6 +312,8 @@ struct mailbox_vfuncs { struct mail **mail_r, bool *tryagain_r); /* Internal search function which updates ctx->seq */ bool (*search_next_update_seq)(struct mail_search_context *ctx); + int (*search_next_match_mail)(struct mail_search_context *ctx, + struct mail *mail); struct mail_save_context * (*save_alloc)(struct mailbox_transaction_context *t); diff --git a/src/plugins/virtual/virtual-storage.c b/src/plugins/virtual/virtual-storage.c index a0779cc186..a57f4f4151 100644 --- a/src/plugins/virtual/virtual-storage.c +++ b/src/plugins/virtual/virtual-storage.c @@ -927,6 +927,7 @@ struct mailbox virtual_mailbox = { virtual_search_deinit, virtual_search_next_nonblock, virtual_search_next_update_seq, + index_storage_search_next_match_mail, virtual_save_alloc, virtual_save_begin, virtual_save_continue,